user-select

Lets you block or ease text selection by the user.

Initial value
auto
Inherited
No
Animatable
no
Applies to
all elements
JavaScript
element.style.userSelect = "none"
On this page

Example

#
CSS
.install-command {
  user-select: all;
  -webkit-user-select: all;
}
Preview

Definition and usage

#

The user-select property controls whether the user can select an element’s text. none blocks selection, all makes a single click select the whole content, and text forces selection to be possible.

user-select: none is useful in interface elements where accidental selection gets in the way, for example buttons clicked many times or draggable cards. The all value works great for fields with code to copy.

Safari still needs the prefixed -webkit-user-select version, so it is worth writing both lines.

Syntax

#
Syntax
user-select: auto | text | none | all;

Values

#
  • auto

    Normal behaviour: the text can be selected.
  • none

    The text cannot be selected.
  • all

    A single click selects the whole paragraph.

Values in practice

#

auto

Normal behaviour: the text can be selected.
.demo { user-select: auto; -webkit-user-select: auto; }

none

The text cannot be selected.
.demo { user-select: none; -webkit-user-select: none; }

all

A single click selects the whole paragraph.
.demo { user-select: all; -webkit-user-select: all; }

Browser support

#

Limited support

Not every browser supports it. Check support before you use it in production.

Good practices

#
  • Don’t block selection in content people may want to copy, such as articles and code.
  • Add -webkit-user-select next to user-select so it works in Safari too.

Related entries

#

Practise it in lessons

#

Spotted a mistake or missing an example? Write to us.