The user-select
CSS property controls whether the user can select text. This doesn't have any effect on content loaded as chrome, except in textboxes.
/* 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: unset; /* Mozilla-specific values */ -moz-user-select: none; -moz-user-select: text; -moz-user-select: all; /* WebKit-specific values */ -webkit-user-select: none; -webkit-user-select: text; -webkit-user-select: all; /* Doesn't work in Safari; use only "none" or "text", or else it will allow typing in the <html> container */ /* Microsoft-specific values */ -ms-user-select: none; -ms-user-select: text; -ms-user-select: element;
Note: user-select
is not an inherited property, though the initial auto
value makes it behave like it is inherited most of the time. WebKit/Chromium-based browsers do implement the property as inherited, which violates the behavior described in the spec, and this will bring some issues. Until now, Chromium chooses to fix the issues, make the final behavior meets the specifications.
none
Selection
object can contain these elements.auto
The used value of auto
is determined as follows:
::before
and ::after
pseudo elements, the used value is none
contain
user-select
on the parent of this element is all
, the used value is all
user-select
on the parent of this element is none
, the used value is none
text
text
all
contain
element
(IE-specific alias)contain
. Supported only in Internet Explorer.Note: CSS UI 4 renames user-select: element
to contain
.
Initial value | auto |
---|---|
Applies to | all elements |
Inherited | no |
Computed value | as specified |
Animation type | discrete |
auto | text | none | contain | all
<p>You should be able to select this text.</p> <p class="unselectable">Hey, you can't select this text!</p> <p class="all">Clicking once will select all of this text.</p>
.unselectable { -moz-user-select: none; -webkit-user-select: none; -ms-user-select: none; user-select: none; } .all { -moz-user-select: all; -webkit-user-select: all; -ms-user-select: all; user-select: all; }
Specification | Status | Comment |
---|---|---|
CSS Basic User Interface Module Level 4 The definition of 'user-select' in that specification. | Working Draft | Initial definition. Also defines -webkit-user-select as a deprecated alias of user-select . |
Desktop | ||||||
---|---|---|---|---|---|---|
user-select |
54
|
12
|
69
|
10
|
15
|
3
|
all |
53 | 79 | 1 | No | 40 | No |
auto |
1 | 12 | 1 | 10 | 15 | 2 |
contain |
No | 12 — 79
|
No | 10
|
No | No |
none |
1 | 12 | 21
|
10 | 15 | 2 |
text |
1 | 12 | 1 | 10 | 15 | 2
|
Mobile | ||||||
---|---|---|---|---|---|---|
user-select |
54
|
54
|
49
|
14
|
3
|
6.0
|
all |
53 | 53 | 4 | 41 | No | 6.0 |
auto |
≤37 | 18 | 4 | 14 | 3 | 1.0 |
contain |
No | No | No | No | No | No |
none |
≤37 | 18 | 21
|
14 | 3 | 1.0 |
text |
≤37 | 18 | 4 | 14 | 3
|
1.0 |
::selection
pseudo-elementSelection
object
© 2005–2020 Mozilla and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/user-select