You’re reading the English version of this content since no translation exists yet for this locale. Help us translate this article!

The Document.createRange() method returns a new Range object.


range = document.createRange();

range is the created Range object.


let range = document.createRange();

range.setStart(startNode, startOffset);
range.setEnd(endNode, endOffset);


Once a Range is created, you need to set its boundary points before you can make use of most of its methods.


Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
createRangeChrome Full support 1Edge Full support 12Firefox Full support YesIE Full support 9Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?


Full support  
Full support
Compatibility unknown  
Compatibility unknown