blob: 8b332ab9c98ca60fe79967391513c4c44a3fde64 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
---
layout: post
title: "Using User-Select"
date: 2019-06-04
---
Highlighting text in order to copy, cut or paste content is a staple action across the web. Now, what if I told you the ability to control what a user can select is configurable with a single CSS property?
## Introducing the CSS property
Simply put, the `user-select` property is defined as follows:
> `user-select` controls whether the user can select text (cursor or otherwise)
## The CSS
The property's available attributes are very straightforward (just remember to target specific browsers for full support!)
/* Default */
p.default {
user-select: auto;
-moz-user-select: auto;
-webkit-user-select: auto;
}
/* Disable the user from selecting text */
p.no-select {
user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
}
/* Select all text when user clicks */
p.select-all {
user-select: all;
-moz-user-select: all;
-webkit-user-select: all;
}
## Let's see it in action
Try selecting the separate paragraph elements in the CodePen below:
[Live CodePen Example](https://codepen.io/bradleytaunt/pen/QRooZp/)
## Browser Support
The great news is `user-select` is fully supported across all modern browsers (even as far back as IE10!)
|