document.caretRangeFromPoint() is a non-standard instance method that returns a Range for the document under viewport coordinates. Learn startContainer / startOffset, when it returns null, shadow DOM limitations, how it compares to caretPositionFromPoint(), and five try-it labs.
01
Kind
Instance method
02
Args
x, y
03
Returns
Range
04
Fields
startContainer
05
Prefer
caretPosition
06
Status
Non-standard
Fundamentals
Introduction
Before the standard caretPositionFromPoint() API, some browsers (especially WebKit-based engines) exposed document.caretRangeFromPoint(x, y) to answer: “where in the document is the text caret at this pixel?”
MDN: it returns a Range object for the document fragment under the specified coordinates. For a collapsed caret at a click point, you typically read range.startContainer and range.startOffset.
⚠️
Fallback only (MDN)
Use this method when caretPositionFromPoint is missing. MDN warns it predates shadow DOM and behaves unpredictably with ShadowRoot objects.
Document.caretRangeFromPoint() is Non-standard on MDN. Logos use the shared browser-image-sprite.png sprite. Historically supported in WebKit/Blink; prefer caretPositionFromPoint() where available.
✓ Non-standard · Legacy fallback
Document.caretRangeFromPoint()
WebKit-era Range API — use caretPositionFromPoint() as the primary path.
LegacyFallback only
Google ChromeSupported (legacy)
Yes
Apple SafariSupported (legacy)
Yes
Microsoft EdgeChromium legacy
Partial
Mozilla FirefoxPrefer caretPositionFromPoint
Partial
OperaChromium legacy
Partial
Internet ExplorerNot supported
No
caretRangeFromPoint()WebKit
Bottom line: Feature-detect caretPositionFromPoint first. Use caretRangeFromPoint only as a fallback on engines that lack the standard API.
Wrap Up
Conclusion
document.caretRangeFromPoint(x, y) is a legacy, non-standard way to get a Range at viewport coordinates. MDN recommends caretPositionFromPoint() instead when supported, and warns about shadow DOM unpredictability.
Five things to remember about caretRangeFromPoint()
Legacy Range API — fallback, not your first choice.
5
Core concepts
📝01
Returns
Range
or null
🚫02
Status
non-standard
MDN
🔗03
Map
startContainer
offset
⚠️04
Shadow
unreliable
MDN
🛡05
Prefer
standard API
2025
❓ Frequently Asked Questions
It returns a Range object (or null) for the document fragment under viewport coordinates x and y — typically with startContainer and startOffset describing the caret position (MDN).
MDN marks it Non-standard only — not Deprecated or Experimental. It is not part of any official specification and is not recommended for new production code when a standard alternative exists.
MDN: use document.caretPositionFromPoint() on supporting browsers (Baseline 2025). It is standard and supports shadowRoots. Keep caretRangeFromPoint() as a fallback for older WebKit-based engines.
A Range, or null if x/y are negative, outside the viewport, or there is no text entry node at that point (MDN).
MDN warns it predates shadow DOM and returns unpredictable, implementation-specific results when ShadowRoot objects are present. Prefer caretPositionFromPoint() with shadowRoots.
range.startContainer ≈ pos.offsetNode and range.startOffset ≈ pos.offset for collapsed caret ranges at a single point.
Did you know?
MDN’s caretPositionFromPoint() live sample uses caretRangeFromPoint() as the WebKit fallback when the standard method is missing—mapping startContainer / startOffset to the same logic as offsetNode / offset.