370

The header for my page has some centered text, but I do not want the user to be able to select it. Is there a way to do this with CSS?

royhowie
  • 11,075
  • 14
  • 50
  • 67
jmasterx
  • 52,639
  • 96
  • 311
  • 557

2 Answers2

718

The CSS below stops users from being able to select text.

-webkit-user-select: none; /* Safari */        
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* IE10+/Edge */
user-select: none; /* Standard */

To target IE9 downwards the html attribute unselectable must be used instead:

<p unselectable="on">Test Text</p>
Karmic Coder
  • 17,569
  • 6
  • 32
  • 42
tw16
  • 29,215
  • 7
  • 63
  • 64
35

Use a simple background image for the textarea suffice.

Or

<div onselectstart="return false">your text</div>
Erre Efe
  • 15,387
  • 10
  • 45
  • 77