Style userSelect attribute

Definition and usage

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

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

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 "user-select" attribute of the element:

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 followed by Webkit, Moz or O specifies 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