The user-select
CSS property controls whether the user can select text. This doesn't have any effect on content loaded as part of a browser's user interface (its chrome), except in textboxes.
The user-select
CSS property controls whether the user can select text. This doesn't have any effect on content loaded as part of a browser's user interface (its 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: revert; user-select: revert-layer; user-select: unset;
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 has chosen to fix the issues to make the final behavior meet the specifications.
none
The text of the element and its sub-elements is not selectable. Note that the 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
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 4 renames user-select: element
to contain
.
Initial value | auto |
---|---|
Applies to | all elements |
Inherited | no |
Computed value | as specified |
Animation type | discrete |
<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 { -webkit-user-select: none; /* Safari */ -ms-user-select: none; /* IE 10+ */ user-select: none; } .all { -webkit-user-select: all; -ms-user-select: all; user-select: all; }
Note: -webkit-user-select: all;
doesn't work in Safari; use only "none" or "text", or else it will allow typing in the <html>
container. See the browser compatibility table for up-to-date information.
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
user-select |
541 | 791212–79 | 69491 | 10 | 4115 | 32–3 | 54≤37 | 5418 | 79494 | 4114 | 3 | 6.01.0 |
all |
53 | 79 | 1 | No | 40 | 16 | 53 | 53 | 4 | 41 | 16 | 6.0 |
auto |
1 | 12 | 1 | 10 | 15 | 2 | ≤37 | 18 | 4 | 14 | 3 | 1.0 |
contain |
No | 12–79 | No | 10 | No | No | No | No | No | No | No | No |
none |
1 | 12 | 211–65 | 10 | 15 | 2 | ≤37 | 18 | 214–65 | 14 | 3 | 1.0 |
text |
1 | 12 | 1 | 10 | 15 | 2Allows typing in the<html> container. |
≤37 | 18 | 4 | 14 | 3Allows typing in the<html> container. |
1.0 |
user-select: contain
::selection
pseudo-elementSelection
object
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/user-select