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.
Fundamentals
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.
Foundation
📝 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)
Defaults
🎯 Default Value
The default value of the user-select property is auto, allowing text selection unless overridden by specific CSS rules or browser settings.
Cheat Sheet
⚡ Quick Reference
Question
Answer
Default value
auto
Disable selection
user-select: none;
One-click select all
user-select: all;
Buttons and nav
user-select: none;
Article body
Keep default auto
Inherited
Yes
Reference
💎 Property Values
The user-select property accepts keyword values that control selection behavior.
Value
Example
Description
auto
user-select: auto;
The default browser behavior, where text selection is allowed.
none
user-select: none;
Text selection is disabled for the element and its children.
text
user-select: text;
Text selection is allowed within the element.
contain
user-select: contain;
Text selection is allowed, but only within the bounds of the element.
all
user-select: all;
A single click selects all text in the element.
autononetextcontainall
Context
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.
Preview
👀 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
Hands-On
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><divclass="no-select"><p>Text inside this div cannot be selected.</p></div>
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.
Companion
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.
Compatibility
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 Chrome54+ · Desktop & Mobile
Full support
Mozilla Firefox69+ · Desktop & Mobile
Full support
Apple Safari3.1+ · macOS & iOS
Full support
Microsoft Edge79+ · All versions
Full support
Opera41+ · All versions
Full support
Testing tip
Test contain separately if you rely on it; support is less consistent than none and all.
user-select property98% supported
Bottom line:user-select is safe to use for UI polish in modern browsers.
Wrap Up
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.