CSS user-select Property

The CSS user-select property controls whether users can select text within an element using a mouse, keyboard, or touch interaction.

It can allow normal text selection, prevent text from being selected, or make an element's entire text content selectable as a single unit. This property is useful for interactive controls, code examples, and interfaces where text selection behavior needs to be customized.

user-select Syntax

The user-select property accepts keywords that determine how text selection behaves within an element.

Basic Syntax

.example {
  user-select: auto;
}

Allow Text Selection

.example {
  user-select: text;
}

Prevent Text Selection

.example {
  user-select: none;
}

Select All Text Together

.example {
  user-select: all;
}

CSS-Wide Keywords

.example {
  user-select: initial;
}
.example {
  user-select: inherit;
}
.example {
  user-select: unset;
}
.example {
  user-select: revert;
}
.example {
  user-select: revert-layer;
}

Invalid Values

.example {
  user-select: yes;
}
.example {
  user-select: enabled;
}
.example {
  user-select: disabled;
}

The values yes, enabled, and disabled are not valid user-select values.

Property Values

Value Description
auto Uses the browser's automatic text selection behavior. This is the initial value.
text Allows normal text selection within the element.
none Prevents the element's text from being selected through normal user selection interactions.
all Causes the element's text content to be selected as a unit when selection begins within it.
contain Intended to restrict a selection started inside the element to that element. Defined in the specification but not interoperably supported.

Property Characteristics

Characteristic Value
Initial value auto
Inherited No, although some browsers implement inherited behavior
Applies to All elements
Computed value As specified
Animation type Discrete
Percentages Not applicable
Specification CSS Basic User Interface Module Level 4

Note: The property controls user selection behavior. It does not remove text from the document, encrypt content, or prevent scripts from accessing text.

How It Works

By default, browsers allow users to select text by dragging across it or using keyboard selection commands.

The user-select property changes how an element participates in those selection interactions.

Step 1: Create Selectable Text

<p class="example">Select this paragraph with your mouse.</p>

Step 2: Allow Normal Selection

.example {
  user-select: text;
}

The user can select individual characters or words in the paragraph.

Step 3: Disable Selection

.example {
  user-select: none;
}

Normal dragging or selection interactions no longer select the paragraph's text.

Step 4: Select the Entire Element

.example {
  user-select: all;
}

Starting a selection inside the element selects its text content as a unit.

Important Distinction

The user-select property affects selection, not whether text is visible or whether it can be accessed through the document source or JavaScript.

The auto Value

The auto value allows the browser to determine selection behavior based on the element and its surrounding context.

Syntax

.example {
  user-select: auto;
}

HTML Example

<p class="default-selection">This paragraph uses automatic text selection.</p>

CSS Example

.default-selection {
  user-select: auto;
}

How It Behaves

For ordinary text, auto generally permits normal selection. Its used behavior can also depend on the selection behavior of parent elements.

Parent Selection Behavior

Under the specification's rules, an element using auto generally behaves as none when its parent uses none, and as all when its parent uses all.

When to Use It

Use auto when the browser's default selection behavior is appropriate.

The text Value

The text value allows users to select text normally within an element.

Syntax

.example {
  user-select: text;
}

HTML Example

<p class="selectable">You can highlight individual words in this paragraph.</p>

CSS Example

.selectable {
  user-select: text;
}

How It Behaves

Users can drag across the text, select individual words, or use supported keyboard selection commands.

Overriding a Parent Rule

.container {
  user-select: none;
}
.container .selectable {
  user-select: text;
}

An explicitly selectable descendant can allow text selection within a region whose parent prevents selection. Exact behavior should be tested across target browsers.

When to Use It

Use text for content that users may need to highlight, quote, or copy, including instructions, reference material, and code examples.

The none Value

The none value prevents text within an element from participating in normal user text selection.

Syntax

.example {
  user-select: none;
}

HTML Example

<div class="non-selectable">This text cannot be selected normally.</div>

CSS Example

.non-selectable {
  user-select: none;
}

How It Behaves

Dragging across the element does not normally highlight its text as part of a user selection.

Interactive Controls

.toolbar-button {
  user-select: none;
}

This can help prevent accidental text highlighting during repeated interactions with custom interface controls.

Important Limitation

The none value is not a content protection mechanism. Users may still access the text through other methods, and scripts can still read it.

When to Use It

Use it selectively for interface elements where text selection interferes with normal interaction. Avoid applying it to entire articles, tutorials, or other content users may want to copy.

The all Value

The all value makes an element's text content behave as a single selectable unit.

Syntax

.example {
  user-select: all;
}

HTML Example

<code class="select-all">https://www.example.com/sample</code>

CSS Example

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

How It Behaves

When a selection starts inside the element, the browser selects the element's entire text content instead of allowing a partial selection within it.

Copyable Code

.copyable-command {
  user-select: all;
}

This can be useful for short commands, URLs, identifiers, and other text that is typically copied in full.

Nested Elements

If nested elements also use user-select: all, selection behavior is based on the relevant selectable unit established by the browser.

Important Consideration

The property selects text but does not automatically copy it to the clipboard. A separate copy action is required.

The contain Value

The contain value is defined in the CSS Basic User Interface specification to restrict the extent of a selection that begins within an element.

Proposed Syntax

.example {
  user-select: contain;
}

Intended Behavior

A selection that begins inside the element would be constrained so it cannot extend beyond the element's boundaries.

Browser Support

The contain value is not interoperably implemented in modern browsers and should not be relied upon for production interfaces.

Historical Note

Some older versions of Internet Explorer and Microsoft Edge supported a related prefixed or legacy value named element. This is not a portable substitute for modern browsers.

Recommended Approach

Use the widely supported values auto, text, none, and all for ordinary selection behavior.

Nested Elements and Selection

Selection behavior can become more complex when a parent and its child elements use different user-select values.

Parent Prevents Selection

.parent {
  user-select: none;
}

Child Allows Selection

.parent .child {
  user-select: text;
}

HTML Example

<div class="parent">
  <p>This parent text is not selectable.</p>
  <p class="child">This child text is explicitly selectable.</p>
</div>

Understanding the Behavior

The child explicitly requests normal text selection even though its parent uses none.

Browser Differences

The specification defines user-select as non-inherited, but some browser engines have historically implemented inherited behavior. This can affect nested selection rules.

Recommended Approach

Apply selection rules to the smallest practical element and test nested combinations in the browsers you support.

Form Controls and Editable Content

Text selection is an important part of interacting with input fields, textareas, and editable content.

Text Input

<input type="text" value="Editable text">

Textarea

<textarea>Users can select and edit this text.</textarea>

Contenteditable Element

<div contenteditable="true">Edit this content.</div>

Selection and Editing

The user-select property does not determine whether an element is editable. Editing is controlled by the element's behavior and HTML attributes such as contenteditable.

Avoid Disabling Selection

Do not apply user-select: none to editable text fields without a specific reason. It can interfere with expected text selection and editing interactions.

Read-Only Text

<input type="text" value="Reference value" readonly>

A read-only input can still allow users to select and copy its value.

Important Consideration

Native form controls may have browser-specific selection behavior that differs from ordinary text elements.

Vendor Prefixes

Some browser versions require or recognize vendor-prefixed versions of user-select.

WebKit Prefix

.example {
  -webkit-user-select: none;
  user-select: none;
}

Mozilla Prefix

.example {
  -moz-user-select: none;
  user-select: none;
}

Microsoft Prefix

.example {
  -ms-user-select: none;
  user-select: none;
}

Combined Declaration

.example {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

Declaration Order

Place the standard unprefixed declaration after any prefixed versions.

Modern Browser Support

The unprefixed property is supported in modern browsers, but -webkit-user-select remains useful for compatibility with some Safari versions.

Recommended Approach

Use the standard property and include only the prefixes needed for your supported browsers. Check current compatibility information before adding legacy declarations.

pointer-events

.example {
  pointer-events: none;
}

Controls whether an element can be targeted by pointer events. It does not provide the same selection behavior as user-select.

cursor

.example {
  cursor: text;
}

Controls the cursor displayed when the pointer is over an element.

caret-color

.example {
  caret-color: blue;
}

Controls the color of the text insertion caret in editable content.

::selection

.example::selection {
  background-color: #cce5ff;
  color: #000;
}

Styles the appearance of highlighted text without changing whether text can be selected.

touch-action

.example {
  touch-action: manipulation;
}

Controls how the browser handles certain touch gestures. It does not replace user-select.

Complete Example

.copyable-text {
  user-select: all;
  cursor: text;
}
.copyable-text::selection {
  background-color: #cce5ff;
  color: #000;
}

This example makes the text selectable as a unit, displays a text cursor, and customizes the selection highlight.

Inheritance

The CSS specification defines user-select as a non-inherited property. However, some browsers have historically implemented it as inherited, creating differences in nested selection behavior.

Parent Element

.parent {
  user-select: none;
}

Child Element

.child {
  user-select: text;
}

Explicit Inheritance

.child {
  user-select: inherit;
}

The inherit keyword explicitly uses the parent's computed value.

Restore the Initial Value

.child {
  user-select: initial;
}

This restores the initial value of auto.

Using unset

.child {
  user-select: unset;
}

Under the standard non-inherited definition, unset behaves like initial.

Important Consideration

The used selection behavior of auto can still depend on the parent element, even though the property itself is defined as non-inherited.

Practical Examples

Prevent Selection on a Toolbar

.toolbar {
  user-select: none;
}

Allow Selection in an Article

article {
  user-select: text;
}

Select a Code Snippet as a Unit

.short-code {
  user-select: all;
}

Prevent Selection on a Drag Handle

.drag-handle {
  cursor: grab;
  user-select: none;
}

Select a Reference Number

.reference-number {
  user-select: all;
}

Allow Selection Inside a Custom Panel

.panel {
  user-select: none;
}
.panel .panel-content {
  user-select: text;
}

Disable Selection on Decorative Labels

.decorative-label {
  user-select: none;
}

Select a URL

.copyable-url {
  user-select: all;
  cursor: text;
}

These examples demonstrate common interface patterns. Selection should remain enabled for content users may need to read, quote, or copy.

user-select Example

This example compares the auto, text, none, and all values. Try dragging across the text in each box to observe the differences.

HTML Example

<div class="selection-demo">
  <div class="selection-row">
    <strong>auto</strong>
    <p class="selection-auto">Select part of this text normally.</p>
  </div>
  <div class="selection-row">
    <strong>text</strong>
    <p class="selection-text">You can highlight individual words here.</p>
  </div>
  <div class="selection-row">
    <strong>none</strong>
    <p class="selection-none">Try selecting this text with your mouse.</p>
  </div>
  <div class="selection-row">
    <strong>all</strong>
    <p class="selection-all">Selecting this text selects the entire paragraph.</p>
  </div>
</div>

CSS Example

.selection-demo {
  display: grid;
  gap: 12px;
}
.selection-row {
  padding: 12px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
}
.selection-row strong {
  display: block;
  margin-bottom: 6px;
}
.selection-row p {
  margin: 0;
}
.selection-auto {
  user-select: auto;
}
.selection-text {
  user-select: text;
}
.selection-none {
  -webkit-user-select: none;
  user-select: none;
}
.selection-all {
  -webkit-user-select: all;
  user-select: all;
}
Browser Result
auto

Select part of this text normally.

text

You can highlight individual words here.

none

Try selecting this text with your mouse.

all

Selecting this text selects the entire paragraph.

Understanding the Results

Each box demonstrates a different selection behavior. Try selecting a few characters, a complete word, or the entire sentence.

auto

The browser uses its normal selection behavior, allowing users to select individual characters and words.

text

The text is explicitly selectable using ordinary selection interactions.

none

Normal user selection is prevented, so dragging across the text does not highlight it.

all

Starting a selection within the paragraph selects the entire paragraph's text as a unit.

Experiment With the Values

Change one of the declarations to another valid value and compare the selection behavior.

.selection-none {
  user-select: text;
}

The previously non-selectable paragraph now permits normal text selection.

Accessibility Considerations

Text selection is an important interaction for many users, including people who copy content, use assistive technologies, or rely on keyboard navigation.

Preserve Selection for Readable Content

Avoid disabling selection on articles, instructions, documentation, and other text users may need to copy or quote.

Use none Selectively

Reserve user-select: none for controls or interface elements where accidental highlighting interferes with interaction.

Do Not Disable Selection for Content Protection

Preventing selection does not protect copyrighted material or stop users from accessing text through other means.

Support Keyboard Interaction

Test selection behavior with keyboard commands as well as mouse and touch interactions.

Avoid Interfering With Editable Content

Users should be able to select, replace, and copy text in editable controls.

Use all Only When Appropriate

Selecting an entire element can be convenient for short values but frustrating for longer content where users need only a portion.

Provide Clear Copy Controls

For code snippets and commands, a dedicated Copy button can provide a more accessible and predictable interaction than relying only on user-select: all.

Test Assistive Technologies

Verify that selection restrictions do not interfere with the intended interaction patterns of screen readers, keyboard users, or other assistive technologies.

Common Mistakes

Using Invalid Values

.example {
  user-select: disabled;
}

Use none to prevent selection.

Disabling Selection on the Entire Page

body {
  user-select: none;
}

This can make ordinary reading and copying tasks unnecessarily difficult.

Assuming none Protects Content

The property does not encrypt or secure text.

Confusing Selection With Pointer Events

.example {
  pointer-events: none;
}

The pointer-events property changes pointer targeting and is not a direct replacement for user-select.

Assuming all Copies Text Automatically

The all value selects text but does not copy it to the clipboard.

Using contain Without Checking Support

The contain value is not interoperably supported in modern browsers.

Ignoring Browser Differences

Nested selection rules and vendor prefixes may behave differently across browsers.

Disabling Selection in Editable Controls

Selection restrictions can interfere with expected text editing interactions.

Confusing user-select With ::selection

The ::selection pseudo-element styles selected text. It does not control whether selection is allowed.

Using all on Long Paragraphs

Users may need to select only part of a long paragraph. Forcing selection of the entire element can reduce usability.

Important Considerations

Keep the following points in mind when using user-select:

  • The property controls normal user text selection behavior.
  • The initial value is auto.
  • The text value allows normal text selection.
  • The none value prevents normal text selection.
  • The all value makes text selectable as a unit.
  • The contain value is not interoperably supported.
  • The property is defined as non-inherited.
  • Some browsers have historically implemented inherited behavior.
  • The used behavior of auto can depend on parent selection rules.
  • The property does not control whether text is editable.
  • The property does not hide or remove text.
  • The property does not prevent JavaScript from accessing text.
  • The property does not provide content security.
  • The all value does not automatically copy text.
  • Selection behavior can vary for nested elements.
  • Native form controls may have special selection behavior.
  • Some browser versions require vendor prefixes.
  • The -webkit-user-select prefix remains relevant for some Safari versions.
  • The property is different from pointer-events.
  • The ::selection pseudo-element controls selection appearance.
  • Avoid disabling selection on ordinary readable content.
  • Use none selectively for interactive controls.
  • Use all for short values intended to be copied in full.
  • Preserve selection in editable fields.
  • Test mouse, keyboard, and touch selection behavior.
  • Consider accessibility before restricting text selection.

Browser Support

The CSS user-select property has broad support across modern browsers, although some implementations still use vendor-prefixed declarations or differ in inheritance behavior.

The commonly used values auto, text, none, and all are supported in modern browser engines, with compatibility details varying by browser version.

The contain value is not interoperably supported and should not be relied upon in production.

For current compatibility information, visit Can I Use? and search for user-select.

Standard Declaration

.example {
  user-select: none;
}

WebKit Compatibility

.example {
  -webkit-user-select: none;
  user-select: none;
}

Legacy Compatibility

.example {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

Feature Detection

@supports (user-select: all) {
  .copyable-text {
    user-select: all;
  }
}

Testing Recommendations

Test selection behavior in the browsers and devices your website supports. Pay particular attention to nested elements, touch interactions, and editable controls.

Specifications

The user-select property is defined in the CSS Basic User Interface Module Level 4 specification.

CSS Basic User Interface Module Level 4 - Content Selection

The specification describes the selection behavior of the property and its values, including the rules for automatic selection and nested elements.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: user-select