EN
CSS - disable text selection
18 points
Using CSS it is possible to remove text selection in the following way:
Quick solution:
xxxxxxxxxx
1
.element {
2
touch-callout: none; /* iOS Safari */
3
user-select: none; /* Safari */
4
user-select: none; /* Konqueror HTML */
5
user-select: none; /* Firefox in the past (old versions) */
6
user-select: none; /* Internet Explorer (>=10) / Edge */
7
user-select: none; /* Currently supported: */
8
/* Chrome, Opera and Firefox */
9
}
Notes:
- some older browsers still does not support
user-select
property, so it is necessary to use prefixes for full capability (Can I use link here),user-select
property is part of CSS4 standard.
This approach removes text selecting option from element with CSS. Read this article to prevent more cases.
xxxxxxxxxx
1
2
<html>
3
<head>
4
<style>
5
6
.disable-selection {
7
touch-callout: none; /* iOS Safari */
8
user-select: none; /* Safari */
9
user-select: none; /* Konqueror HTML */
10
user-select: none; /* Firefox in the past (old versions) */
11
user-select: none; /* Internet Explorer (>=10) / Edge */
12
user-select: none; /* Currently supported: */
13
/* Chrome, Opera and Firefox */
14
}
15
16
div {
17
margin: 10px;
18
padding: 20px;
19
}
20
21
</style>
22
</head>
23
<body>
24
<div class="disable-selection" style="background: silver">
25
This text is not selectable ...
26
</div>
27
<div style="background: gold">
28
This text is selectable ...
29
</div>
30
</body>
31
</html>