Favorites

HTML onselectstart Event Attribute

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
onselectstart
HTML Event AttributeThis event attribute is supported in some modern browsers, but not all.
Updated 22nd November 2026

Description

The onselectstart event attribute runs a script when the user starts a new text selection, for example by pressing the mouse button and starting to drag over text.

The event bubbles and is cancelable: calling event.preventDefault() (or returning false from the attribute) stops the selection from starting. The CSS user-select: none property is usually a better way to make text unselectable, but onselectstart can decide at the moment the selection begins. Use onselectionchange to react to the selection as it changes.

Syntax

<element onselectstart="script">

Values

  • scriptThe name of the script to use when the event has been triggered.

Example

<!DOCTYPE html>
<html>
<head>
<title>onselectstart event</title>
</head>
<body>
<p onselectstart="log('selectstart')">You can select this paragraph.</p>
<p onselectstart="log('selection blocked'); return false">You cannot select this paragraph.</p>
<ul id="log"></ul>
<script>
function log(text) {
var li = document.createElement("li");
li.textContent = text;
document.getElementById("log").appendChild(li);
}
</script>
</body>
</html>
Open in editor

Browser Support

The following information will show you the current browser support for the HTML onselectstart event attribute. Hover over a browser icon to see the version that first introduced support for this HTML event attribute.

This event attribute is supported in some modern browsers, but not all.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee