CaretPosition: getClientRect() method

Baseline 2025
Newly available

Since December 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

The getClientRect() method of the CaretPosition interface returns the client rectangle for the caret range.

Syntax

js
getClientRect()

Parameters

None.

Return value

A DOMRect object.

Examples

Get the caret's screen position

html
<input aria-label="text field" value="Click inside this input field" />
js
document.querySelector("input").addEventListener("click", (event) => {
  const x = event.clientX;
  const y = event.clientY;

  const caret = document.caretPositionFromPoint?.(x, y);
  if (!caret) {
    log("Not supported");
    return;
  }

  const rect = caret.getClientRect();

  log(`Caret bounding rect: ${JSON.stringify(rect)}`);
  log(`Caret is at (${rect.x.toFixed(2)}, ${rect.y.toFixed(2)})`);
});

Specifications

Specification
CSSOM View Module
# dom-caretposition-getclientrect

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
getClientRect
Chrome – Full support
Chrome 128 (Release date: 2024-08-20)
footnote Full support
Edge – Full support
Edge 128 (Release date: 2024-08-22)
footnote Full support
Firefox – Full support
Firefox 23 (Release date: 2013-08-06)
footnote Full support
Opera – Full support
Opera 114 (Release date: 2024-09-25)
footnote Full support
Safari – Full support
Safari 26.2 (Release date: 2025-12-12)
footnote Full support
Chrome Android – Full support
Chrome Android 128 (Release date: 2024-08-20)
footnote Full support
Firefox for Android – Full support
Firefox for Android 23 (Release date: 2013-08-06)
footnote Full support
Opera Android – Full support
Opera Android 85 (Release date: 2024-10-29)
footnote Full support
Safari on iOS – Full support
Safari on iOS 26.2 (Release date: 2025-12-12)
footnote Full support
Samsung Internet – Full support
Samsung Internet 28 (Release date: 2025-04-02)
footnote Full support
WebView Android – Full support
WebView Android 128 (Release date: 2024-08-20)
footnote Full support
WebView on iOS – Full support
WebView on iOS 26.2 (Release date: 2025-12-12)
footnote Full support

Legend

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

Full support
Full support

See also