CSS user-select Property

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 4 Examples
UI & Interaction

What You’ll Learn

The user-select property lets you allow or block text selection — useful for buttons, drag interfaces, and copy-friendly code snippets.

01

Selection

Allow or block.

02

none

Disable select.

03

auto

Default behavior.

04

all

One-click select.

05

Buttons

No highlight drag.

06

A11y

Don’t over-block.

Introduction

The user-select property in CSS allows developers to control whether text can be selected by the user. This property is particularly useful for improving the user experience on web pages where selecting text might interfere with interactive elements or design layouts.

Definition and Usage

Apply user-select: none on UI controls like buttons, tabs, and draggable cards to prevent accidental blue highlights. Use user-select: all on tokens or code snippets when you want one click to select the entire value for copying.

💡
Beginner Tip

Do not disable selection on long article body text. Reserve user-select: none for interactive UI, not readable content users may need to copy.

📝 Syntax

The syntax for the user-select property is straightforward. It can be applied to any element and accepts different values to control text selection behavior.

syntax.css
element {
  user-select: value;
}

Basic Example

user-select.css
.no-select {
  user-select: none;
}

Syntax Rules

  • Keyword values: auto, none, text, all, contain.
  • The property is inherited by child elements.
  • none on a parent blocks selection for descendants unless overridden.
  • Older browsers used vendor prefixes; modern browsers support the standard property.

Related Properties

  • cursor — changes the mouse pointer on hover
  • pointer-events — controls whether an element receives pointer events
  • -webkit-touch-callout — iOS callout menu on long-press (legacy)

🎯 Default Value

The default value of the user-select property is auto, allowing text selection unless overridden by specific CSS rules or browser settings.

⚡ Quick Reference

QuestionAnswer
Default valueauto
Disable selectionuser-select: none;
One-click select alluser-select: all;
Buttons and navuser-select: none;
Article bodyKeep default auto
InheritedYes

💎 Property Values

The user-select property accepts keyword values that control selection behavior.

ValueExampleDescription
autouser-select: auto;The default browser behavior, where text selection is allowed.
noneuser-select: none;Text selection is disabled for the element and its children.
textuser-select: text;Text selection is allowed within the element.
containuser-select: contain;Text selection is allowed, but only within the bounds of the element.
alluser-select: all;A single click selects all text in the element.
auto none text contain all

When to Use user-select

Choose a value based on how users should interact with the content:

  • Buttons and toolbars — Use none to prevent label highlighting on click.
  • Draggable cards — Avoid text selection fighting with drag gestures.
  • API keys and code tokens — Use all for quick copy on one click.
  • Articles and docs — Keep default selection so users can copy paragraphs.

👀 Live Preview

Try selecting text in each box below:

This text uses the default auto behavior and can be selected.
auto (default)
This text has user-select: none and cannot be selected.
user-select: none

Examples Gallery

In this example, we’ll disable text selection for a specific div element.

📜 Core Patterns

Block or allow text selection with a single CSS property.

Example 1 — Disable selection on a div

In this example, we’ll disable text selection for a specific div element.

index.html
<style>
  .no-select {
    user-select: none;
  }
</style>

<div class="no-select">
  <p>Text inside this div cannot be selected.</p>
</div>
Try It Yourself

How It Works

user-select: none tells the browser not to start a text selection inside this element when the user clicks and drags.

Example 2 — Selectable vs blocked

Place default and none side by side to see the difference.

compare.css
.blocked {
  user-select: none;
}
Try It Yourself

How It Works

Because user-select is inherited, children inside .blocked also cannot be selected unless reset to text or auto.

📄 UI Patterns

Apply user-select in real interface components for smoother interaction.

Example 3 — Buttons without text highlight

Prevent button labels from being selected when users click or drag across a toolbar.

buttons.css
.btn {
  user-select: none;
  cursor: pointer;
}
Try It Yourself

How It Works

Interactive controls feel more polished when accidental text selection does not flash during rapid clicks.

Example 4 — One-click select with all

Make an API key or code token select entirely on one click for easy copying.

all.css
.token {
  user-select: all;
  font-family: monospace;
}
Try It Yourself

How It Works

user-select: all selects the entire element’s text content in one action, which is helpful for copy-paste workflows.

♿ Accessibility

  • Do not block article text — Users need to copy tutorials, error messages, and documentation.
  • Keyboard selectionuser-select: none affects mouse/touch selection; ensure critical content remains reachable.
  • Provide copy affordances — If you use none on tokens, consider a dedicated Copy button as well.
  • Avoid overuse — Disabling selection on large page regions harms usability and accessibility.

user-select + cursor

Pair user-select: none with cursor: pointer on clickable UI so users know the element is interactive, not static text.

ui-control.css
.tab {
  user-select: none;
  cursor: pointer;
}

🧠 How user-select Works

1

User interacts with text

Click, drag, double-click, or keyboard selection is attempted.

Input
2

Browser checks user-select

The computed value on the element and ancestors determines if selection is allowed.

Rules
3

Selection allowed or blocked

none stops highlighting; all selects everything at once.

Result
=

Controlled UX

Text selection matches the intended interaction model.

Browser Compatibility

The user-select property is supported in most modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. However, browser support for specific values like contain may vary. It’s recommended to test your implementation across different browsers to ensure consistent behavior.

Modern browsers · Widely supported

Text selection control

user-select: none and user-select: all work in current Chrome, Firefox, Safari, Edge, and Opera.

98% Browser support
Google Chrome 54+ · Desktop & Mobile
Full support
Mozilla Firefox 69+ · Desktop & Mobile
Full support
Apple Safari 3.1+ · macOS & iOS
Full support
Microsoft Edge 79+ · All versions
Full support
Opera 41+ · All versions
Full support

Testing tip

Test contain separately if you rely on it; support is less consistent than none and all.

user-select property 98% supported

Bottom line: user-select is safe to use for UI polish in modern browsers.

Conclusion

The user-select property is a valuable tool for web developers aiming to enhance user experience by controlling text selection behavior on their websites.

By strategically applying this property, you can improve usability and prevent unintended interactions with text content. Experiment with different values to find the best approach for your design and functionality needs.

💡 Best Practices

✅ Do

  • Use none on buttons, tabs, and draggable UI
  • Use all on copy-friendly tokens and short code values
  • Keep article and documentation text selectable
  • Pair with cursor: pointer on interactive controls
  • Test on touch devices where long-press may select text

❌ Don’t

  • Apply none to entire page content
  • Block selection as a substitute for proper copy buttons on long text
  • Forget that user-select is inherited by children
  • Rely on none alone for security — it is not copy protection

Key Takeaways

Knowledge Unlocked

Five things to remember about user-select

Use these points when controlling text selection.

5
Core concepts
🕐 02

auto

Default value.

Default
🚫 03

none

UI controls.

Pattern
📋 04

all

Quick copy.

Pattern
📚 05

Inherited

Affects children.

Behavior

❓ Frequently Asked Questions

user-select controls whether the user can select text in an element with the mouse, touch, or keyboard.
The default is auto, which follows normal browser selection behavior.
Set user-select: none on the button or its container to stop accidental text highlighting during clicks and drags.
none disables selection. text allows normal text selection within the element.
Yes, user-select is inherited. Setting it on a parent affects child elements unless they override it.

Practice in the Live Editor

Open the HTML editor and test user-select on buttons, text, and tokens.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful