Style userSelect attribute

Definition and usage

userSelect Attribute setting or return whether the text of an element can be selected.

If you double-click on some text, it will be selected/highlighted. This attribute can be used to prevent this.

See also:

CSS Reference Manual:user-select attribute

Instance

Example 1

Prevent text selection of the <div> element:

document.getElementById("myDiv").style.userSelect = "none";

Try it yourself

Example 2

Get the value of the element's "user-select" attribute:

document.getElementById("demo").style.userSelect;

Try it yourself

Syntax

Return the userSelect attribute:

object.style.userSelect

Set the userSelect attribute:

object.style.userSelect = "auto|none|text|all"

Attribute value

Value Description
auto Default. Text can be selected according to the browser's default settings.
none Prevent text selection.
text Text can be selected by the user.
all Select text by clicking instead of double-clicking.

Technical details

Default value: auto
Return value: A string indicating whether the text of an element can be selected.
CSS version: CSS3

Browser support

The numbers in the table indicate the first browser version that fully supports this property.

The number is followed by Webkit, Moz, or O to specify the first version using the prefix.

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
54.0 79.0
10.0 ms
69.0 3.1 Webkit 41.0