Control how the text of an element is selected and whether the element responds to pointer events.
Text selection
User-select utilities set the CSS user-select property, controlling how text within an element responds to pointer selection.
This paragraph will be entirely selected when clicked by the user.
This paragraph has default select behavior.
This paragraph will not be selectable when clicked by the user.
<p class="user-select-all">This paragraph will be entirely selected when clicked by the user.</p>
<p class="user-select-auto">This paragraph has default select behavior.</p>
<p class="user-select-none">This paragraph will not be selectable when clicked by the user.</p>Pointer events
Pointer event utilities set the CSS pointer-events property. .pointer-event-none disables mouse, stylus, and touch interactions. .pointer-event-auto restores the default behavior, or overrides an inherited disabled state.
This link can not be clicked.
This link can be clicked (this is default behavior).
This link can not be clicked because the pointer-events property is inherited from its parent. However, this link has a pointer-event-auto class and can be clicked.
<p><a href="#" class="pointer-event-none" tabindex="-1" aria-disabled="true">This link</a> can not be clicked.</p>
<p><a href="#" class="pointer-event-auto">This link</a> can be clicked (this is default behavior).</p>
<p class="pointer-event-none"><a href="#" tabindex="-1" aria-disabled="true">This link</a> can not be clicked because the <code>pointer-events</code> property is inherited from its parent. However, <a href="#" class="pointer-event-auto">this link</a> has a <code>pointer-event-auto</code> class and can be clicked.</p>.pointer-event-none affects only pointer-based interactions. An element with this class stays focusable and can be activated with the keyboard. Add tabindex="-1" to take it out of the keyboard focus order, and aria-disabled="true" to convey the disabled state to assistive technologies.
Native attributes cover the common cases without the class:
- For form inputs, add the
disabledHTML attribute. - For links, remove the
hrefattribute, which makes the anchor a non-interactive placeholder link.
CSS
Interaction utilities are generated via the utilities API.
Reference
The table lists all interaction utilities and their CSS properties.
| Class | Properties |
|---|---|
.user-select-all | -webkit-user-select: all; |
.user-select-auto | -webkit-user-select: auto; |
.user-select-none | -webkit-user-select: none; |
.pointer-event-none | pointer-events: none; |
.pointer-event-auto | pointer-events: auto; |
Utilities API
Interaction utilities are declared in scss/utilities/_index.scss using the utilities API.
"user-select": (
property: user-select,
values: all auto none
),
"pointer-events": (
property: pointer-events,
class: pointer-event,
values: none auto,
),