Document: caretRangeFromPoint() method

Non-standard: This feature is not standardized. We do not recommend using non-standard features in production, as they have limited browser support, and may change or be removed. However, they can be a suitable alternative in specific cases where no standard option exists.

The caretRangeFromPoint() method of the Document interface returns a Range object for the document fragment under the specified coordinates.

This method predates the concept of shadow DOM, and will return unpredictable and implementation-specific results in a document that contains ShadowRoot objects.

Use caretPositionFromPoint() instead on supporting browsers because it is a standard method that can return the caret position from within ShadowRoot instances, provided the relevant shadow roots are passed in its options parameter.

Syntax

js
caretRangeFromPoint(x, y)

Parameters

x

A horizontal position within the current viewport.

y

A vertical position within the current viewport.

Return value

One of the following:

  • A Range.
  • null, if x or y are negative, outside the viewport, or there is no text entry node.

Examples

Visit the Document.caretPositionFromPoint() page to view a live sample of this method.

Specifications

Not part of any specification.

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
caretRangeFromPoint
Non-standard
Chrome – Full support
Chrome 4 (Release date: 2010-01-25)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 150 (Release date: 2026-04-21)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 5 (Release date: 2010-06-07)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 150 (Release date: 2026-04-21)
footnote Full support
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 4 (Release date: 2010-06-21)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 4 (Release date: 2010-06-21)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Non-standard. Check cross-browser support before using.

See also