user-select

Theuser-selectCSSproperty controls whether the user can select text. This doesn't have any effect on content loaded as part of a browser's user interface (itschrome), except in textboxes.

Try it

Syntax

css
/* Keyword values */
user-select:none;
user-select:auto;
user-select:text;
user-select:contain;
user-select:all;

/* Global values */
user-select:inherit;
user-select:initial;
user-select:revert;
user-select:revert-layer;
user-select:unset;

Note:user-selectis not an inherited property, though the initialautovalue makes it behave like it is inherited most of the time. WebKit/Chromium-based browsersdoimplement the property as inherited, which violates the behavior described in the spec, and this will bring some issues. Until now, Chromium has chosen tofix the issuesto make the final behavior meet the specifications.

Values

none

The text of the element and its sub-elements is not selectable. Note that theSelectionobject can contain these elements.

auto

The used value ofautois determined as follows:

  • On the::beforeand::afterpseudo elements, the used value isnone
  • If the element is an editable element, the used value iscontain
  • Otherwise, if the used value ofuser-selecton the parent of this element isall,the used value isall
  • Otherwise, if the used value ofuser-selecton the parent of this element isnone,the used value isnone
  • Otherwise, the used value istext
text

The text can be selected by the user.

all

The content of the element shall be selected atomically: If a selection would contain part of the element, then the selection must contain the entire element including all its descendants. If a double-click or context-click occurred in sub-elements, the highest ancestor with this value will be selected.

contain

Enables selection to start within the element; however, the selection will be contained by the bounds of that element.

Note:CSS UI 4renamedtheelementvalue tocontain.

Formal definition

Initial valueauto
Applies toall elements
Inheritedno
Computed valueas specified
Animation typediscrete

Formal syntax

user-select =
auto|
text|
none|
contain|
all

Examples

HTML

html
<p>You should be able to select this text.</p>
<pclass="unselectable">Hey, you can't select this text!</p>
<pclass="all">Clicking once will select all of this text.</p>

CSS

css
.unselectable{
-webkit-user-select:none;/* Safari */
user-select:none;
}

.all{
-webkit-user-select:all;
user-select:all;
}

Result

Specifications

Specification
CSS Basic User Interface Module Level 4
#content-selection

Browser compatibility

BCD tables only load in the browser

See also