What is the user-select property in CSS?
The user-select property is used to define how text selection should happen.
We can set two values to change the text selection property:
none– Disables the text selectionall– Selects all the content of the element with a single click.
-
If the parent’s user-select is set to
alland the child doesn’t have user-select, then all contents are selected when clicking the child or parent. -
If the parent’s user-select is set to
noneand the child doesn’t have user-select, then the child contents cannot be selected. -
If the child’s user-select is set to
alland the parent doesn’t have user-select, then the parent will not click on the child. -
If the child’s user-select is set to
noneand the parent’s user-select is set toall, then the child will not click the parent.
If an element doesn’t have a user-select property, the default value is set to auto. The auto property means:
-
For the
::beforeand::afterpseudo-elements, the value of user-select isnone. -
For the editable elements, like
input textarea, the user-select value is contained. -
The user-select property of the parent is used.
-
Other than this, the user-select value is
text.