MDN’s new design is in Beta! A sneak peek:

range Redirect 1

« DOM Reference

The Range interface represents a fragment of a document that can contain nodes and parts of text nodes in a given document.

A range can be created using the createRange method of the Document object. Range objects can also be retrieved by using the getRangeAt method of the Selection object. There also is the Range() constructor available.


There are no inherited property.

Range.collapsed Read only
Returns a Boolean indicating whether the range's start and end points are at the same position.
Range.commonAncestorContainer Read only
Returns the deepest Node that contains the startContainer and endContainer nodes.
Range.endContainer Read only
Returns the Node within which the Range ends.
Range.endOffset Read only
Returns a number representing where in the endContainer the Range ends.
Range.startContainer Read only
Returns the Node within which the Range starts.
Range.startOffset Read only
Returns a number representing where in the startContainer the Range starts.


Returns a Range object with the global Document as its start and end.


There are no inherited method.

Sets the start position of a Range.
Sets the end position of a Range.
Sets the start position of a Range relative to another Node.
Sets the start position of a Range relative to another Node.
Sets the end position of a Range relative to another Node.
Sets the end position of a Range relative to another Node.
Sets the Range to contain the Node and its contents.
Sets the Range to contain the contents of a Node.
Collapses the Range to one of its boundary points.
Returns a DocumentFragment copying the nodes of a Range.
Removes the contents of a Range from the Document.
Moves contents of a Range from the document tree into a DocumentFragment.
Insert a Node at the start of a Range.
Moves content of a Range into a new Node.
Compares the boundary points of the Range with another one.
Returns a Range object with boundary points identical to the cloned Range.
Releases the Range from use to improve performance.
Returns the text of the Range.
Returns a constant representing whether the Node is before, after, inside, or surrounding the range.
Returns -1, 0, or 1 indicating whether the point occurs before, inside, or after the Range.
Returns a DocumentFragment created from a given string of code.
Returns a ClientRect object which bounds the entire contents of the Range; this would be the union of all the rectangles returned by range.getClientRects().
Returns a list of ClientRect objects that aggregates the results of Element.getClientRects() for all the elements in the Range.
Returns a boolean indicating whether the given node intersects the Range.
Returns a boolean indicating whether the given point is in the Range.


Specification Status Comment
DOM Living Standard Do not use RangeException anymore, use DOMException instead.
Made the second parameter of collapse() optional.
Added the methods isPointInRange(), comparePoint(), and intersectsNode().
Added the constructor Range().
DOM Parsing and Serialization Living Standard Added the method createContextualFragment().
CSS Object Model (CSSOM) View Module Working Draft Added the methods getClientRects() and getBoundingClientRect().
Document Object Model (DOM) Level 2 Traversal and Range Specification Recommendation Initial specification.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) 1.0 (1.7 or earlier) [1] 9.0 9.0 (Yes)
Range() constructor (Yes) 24.0 (24.0) Not supported 15.0 (Yes)
compareNode() Not supported 1.0 (1.7 or earlier)
Removed in 3.0 (1.9)
Not supported Not supported Not supported
isPointInRange(), and comparePoint() (Yes) (Yes) Not supported 15.0 ?
intersectsNode() (Yes) 17.0 (17.0) [2] Not supported 15.0 ?
getClientRects() and getBoundingClientRect() (Yes) 4.0 (2.0) Not supported 15.0 ?
createContextualFragment() (Yes) (Yes) Not supported 15.0 ?
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) 1.0 (1.0) [1] 9.0 9.0 (Yes)

[1] Starting with Gecko 13.0 (Firefox 13.0 / Thunderbird 13.0 / SeaMonkey 2.10) the Range object throws a DOMException as defined in DOM 4, instead of a RangeException defined in prior specifications.

[2] Gecko supported it up to Gecko 1.9, then removed it until Gecko 17 where it was reimplemented, matching the spec.

See also

Document Tags and Contributors

 Last updated by: Sheppy,