SelectionBaseline · Widely available
The Selection API controls and modifies user text selections within the page.
Supported in all major browsers for at least 30 months — safe to use without fallbacks. Baseline since Mar 7, 2017. Widely available since Sep 7, 2019.
Browser support
DesktopChrome
1–10Not supported
11+Supportedsince Apr 27, 2011
Current: 155Edge
12+Supportedsince Jul 29, 2015
Current: 154Firefox
1–51Not supported
52+Supportedsince Mar 7, 2017
Current: 157Safari
1–5Not supported
5.1+Supportedsince Jul 20, 2011
Current: 27MobileChrome Android
18+Supportedsince Jun 27, 2012
Current: 155Firefox Android
4–51Not supported
52+Supportedsince Mar 7, 2017
Current: 157Safari iOS
1–4.2Not supported
5+Supportedsince Oct 12, 2011
Current: 27How to use
This feature is Baseline widely available — use it freely, no fallback needed.
Example
Full syntax and examples are on MDN: AbstractRange.
Feature detection
JS · check before using
if ("Selection" in globalThis) {
// Selection is available
} else {
// load a polyfill or use a fallback
}Documentation (MDN)
Specification
Usage share
Sub-features
Support for each part of the feature (79). The overall table above shows when the whole feature works.
| Sub-feature | Chrome | Edge | Firefox | Safari | Chrome Android | Firefox Android | Safari iOS |
|---|---|---|---|---|---|---|---|
| AbstractRange | 90 | 90 | 69 | 14.1 | 90 | 79 | 14.5 |
| AbstractRange.collapsed | 90 | 90 | 69 | 14.1 | 90 | 79 | 14.5 |
| AbstractRange.endContainer | 90 | 90 | 69 | 14.1 | 90 | 79 | 14.5 |
| AbstractRange.endOffset | 90 | 90 | 69 | 14.1 | 90 | 79 | 14.5 |
| AbstractRange.startContainer | 90 | 90 | 69 | 14.1 | 90 | 79 | 14.5 |
| AbstractRange.startOffset | 90 | 90 | 69 | 14.1 | 90 | 79 | 14.5 |
| Document.createRange | 1 | 12 | 1 | 1 | 18 | 4 | 1 |
| Document.getSelection | 2 | 12 | 57 | 4 | 18 | 57 | 3.2 |
| Document.selectionchange_event | 11 | 12 | 52 | 5.1 | 18 | 52 | 5 |
| HTMLInputElement.selectionchange_event | 127 | 127 | 92 | 18 | 127 | 92 | 18 |
| HTMLTextAreaElement.selectionchange_event | 127 | 127 | 92 | 18 | 127 | 92 | 18 |
| Node.selectstart_event | 1 | 12 | 52 | 1.3 | 18 | 52 | ✕ |
| Range | 1 | 12 | 1 | 1 | 18 | 4 | 1 |
| Range.Range | 29 | 15 | 24 | 8 | 29 | 24 | 8 |
| Range.cloneContents | 1 | 12 | 1 | 1 | 18 | 4 | 1 |
| Range.cloneRange | 1 | 12 | 1 | 1 | 18 | 4 | 1 |
| Range.collapse | 1 | 12 | 1 | 1 | 18 | 4 | 1 |
| Range.collapse.toStart_parameter_optional | 1 | 16 | 25 | 1 | 18 | 25 | 1 |
| Range.collapsed | 1 | 12 | 1 | 1 | 18 | 4 | 1 |
| Range.commonAncestorContainer | 1 | 12 | 1 | 1 | 18 | 4 | 1 |