The
selectstart
event fires when a user starts a new selection. Learn
addEventListener vs onselectstart, how
preventDefault() blocks the selection, and why MDN marks this event
Limited availability—plus how it fits the Selection API next to
addEventListener().
01
Kind
DOM event
02
Type
Event
03
Bubbles
Yes
04
Cancelable
Yes
05
Handler
onselectstart
06
Status
Limited availability
Fundamentals
Introduction
When someone presses and drags to highlight text, the browser is about to create a new
selection range. Right before that change (in the cases the Selection API defines), it
fires selectstart.
MDN: if the event is canceled, the selection is not changed. That makes
selectstart useful for “do not allow selecting this content”
patterns—with the caveat that support is not universal on every mobile browser.
💡
Beginner tip
Prefer addEventListener("selectstart", ...) so you can attach
multiple handlers and remove them cleanly. The onselectstart property is
fine for quick demos.
Concept
Understanding selectstart
Part of the Selection API. It answers: “The user is starting a new
selection—should we allow it?”
Fires when a user starts a new selection.
Cancel with preventDefault() to keep the selection unchanged.
Generic Event — no special payload properties beyond a normal Event.
Limited availability — not Baseline; test Safari iOS carefully.
Foundation
📝 Syntax
Use the event name with addEventListener, or set the handler property:
Per the Selection API, selectstartbubbles and is
cancelable. Canceling it means the user agent must not change the
selection.
Compare
⚖️ selectstart vs select vs selectionchange
Event
When it fires
Typical use
selectstart
User starts a new selection
Detect or block selection start
select
Selection inside some form controls changes
<input> / <textarea> selection
selectionchange
Current selection changes
React after the selection updates
Caveat
⚠️ Limited Availability (Not Baseline)
MDN labels selectstart as Limited availability: it is not
Baseline because it does not work in some widely used browsers. Desktop Chrome, Firefox,
Edge, and Safari generally support it; Safari on iOS is a common gap.
It is still a standard Selection API event—not Deprecated, Experimental, or
Non-standard. For “no copy” UX, also consider CSS
user-select: none as a complementary approach.
Cheat Sheet
⚡ Quick Reference
Goal
Code
Listen on document
document.addEventListener("selectstart", fn)
Handler property
document.onselectstart = fn
Block selection
event.preventDefault()
Scoped listen
el.addEventListener("selectstart", fn)
Read selection later
document.getSelection()
MDN status
Limited availability (not Baseline)
Snapshot
🔍 At a Glance
Four facts to remember about the selectstart event.
Event type
Event
Generic
Cancelable
yes
preventDefault
Bubbles
yes
Selection API
Baseline
no
Limited availability
Hands-On
Examples Gallery
Examples follow
MDN Node: selectstart event.
Try It Yourself labs let you drag-select text and watch the log. Use View Output for the
expected console messages from the sample handlers.
📚 Getting Started
Register handlers the MDN ways.
Example 1 — addEventListener("selectstart")
MDN: listen on document and log when selection starts.
JavaScript
document.addEventListener("selectstart", () => {
console.log("Selection started");
});
// Drag to highlight any text on the page to fire the event.
Same event, different registration API. Prefer addEventListener when you
need more than one handler.
📈 Cancel, Scope & Selection
Block selection, listen on one element, read the Selection object.
Example 3 — Cancel Selection with preventDefault()
MDN: if the event is canceled, the selection is not changed.
JavaScript
document.addEventListener("selectstart", (event) => {
event.preventDefault();
console.log("Selection blocked");
});
// Attempting to drag-select text should not create a highlight
// (where selectstart is supported).
Because the event is cancelable, preventDefault() tells the browser not
to apply the new selection. Pair with CSS user-select for broader coverage.
Example 4 — Listen on One Element Only
Attach to a container so you only react when selection starts inside it (via bubbling).
JavaScript
const box = document.getElementById("protect");
box.addEventListener("selectstart", (event) => {
console.log("selectstart inside #protect");
console.log("target:", event.target.nodeName);
});
// Selecting text outside #protect will not hit this listener
// unless the event bubbles through another ancestor you also listen on.
The event bubbles, so a parent can observe starts that originate on descendant text.
Use event.target to see where it began.
Example 5 — After Start, Read getSelection()
Log when selection starts; optionally inspect the Selection on the next tick.
JavaScript
document.addEventListener("selectstart", () => {
console.log("Selection started");
// Selection may still be empty/collapsed at the very start;
// read again after the user finishes dragging if you need the final text.
requestAnimationFrame(() => {
const sel = document.getSelection();
console.log("isCollapsed:", sel ? sel.isCollapsed : null);
});
});
selectstart is a standard Selection API event, but MDN marks it Limited availability (not Baseline). Logos use the shared browser-image-sprite.png sprite from this project. Desktop engines generally support it; Safari on iOS is a notable gap—always verify on real devices.
✓
Limited availability · Not Baseline
Node selectstart
Works on major desktop browsers; missing or unreliable on some mobile browsers (e.g. Safari iOS).
LimitedNot Baseline
Google ChromeSupported · Desktop & Android
Full support
Mozilla FirefoxSupported since Firefox 52+
Full support
Apple SafariDesktop yes · iOS typically no
Partial
Microsoft EdgeSupported · Chromium
Full support
OperaSupported · Modern versions
Full support
Internet ExplorerLong-standing support in legacy IE
Full support
selectstartLimited
Bottom line: Cancelable selection-start event; pair with CSS user-select and test Safari iOS.
Wrap Up
Conclusion
selectstart lets you react when a user begins a selection—or cancel that
start with preventDefault(). Use addEventListener for flexible
handlers, remember it is not Baseline everywhere, and combine with CSS when you need
stronger “no select” UX.
Prefer addEventListener over a single onselectstart
Call preventDefault() only when you truly need to block selection
Test on Safari iOS and other mobile browsers
Use CSS user-select as a complementary control
Read final text via selectionchange or mouseup
❌ Don’t
Assume Baseline support on every device
Confuse with the form-control select event
Expect rich event fields—it is a generic Event
Confuse DOM Node with the Node.js runtime
Block all selection without an accessibility-friendly reason
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about selectstart
Selection is about to begin—listen or cancel.
5
Core concepts
📄01
Starts selection
user gesture
Event
🚫02
Cancelable
preventDefault
API
📡03
Bubbles
parent listen
DOM
⚠️04
Not Baseline
limited
Compat
🎨05
Use CSS too
user-select
UX
❓ Frequently Asked Questions
It is a Selection API event fired when a user starts a new selection (for example dragging to highlight text). If you cancel the event, the selection is not changed.
No. MDN does not mark Node selectstart as Deprecated, Experimental, or Non-standard. It is a standard Selection API event, but MDN labels it Limited availability (not Baseline) because support is missing in some browsers—notably Safari on iOS.
A generic Event. It bubbles and is cancelable (per the Selection API). Call event.preventDefault() to block the new selection.
Use addEventListener("selectstart", handler) or the onselectstart property on document, window, or an element that participates in selection.
The HTML select event (and onselect) typically fires when selection inside an <input> or <textarea> changes. selectstart fires when a new selection begins in the document (often for general text selection), and canceling it prevents that selection from starting.
Can I Use / MDN compatibility data show selectstart unsupported on Safari iOS. Desktop Safari supports it. Always test on your target devices and provide a fallback if blocking selection is critical on iOS.
Did you know?
The Selection API says the user agent must not fire selectstart when
it merely sets the selection empty. So clearing a selection is a different story from
starting a new one—listen for selectionchange if you need both moments.