Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make certain text not selectable with CSS [duplicate]

Tags:

css

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?

like image 617
jmasterx Avatar asked Aug 01 '11 14:08

jmasterx


People also ask

How do you prevent text from selection in CSS?

You can use the user-select property to disable text selection of an element. In web browsers, if you double-click on some text it will be selected/highlighted. This property can be used to prevent this.

How do I select non selectable text?

Copying text is no rocket science. You just need to highlight the subject with your cursor and use the keyboard shortcut CTRL +C.


2 Answers

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> 
like image 122
tw16 Avatar answered Sep 17 '22 19:09

tw16


Use a simple background image for the textarea suffice.

Or

<div onselectstart="return false">your text</div> 
like image 43
Erre Efe Avatar answered Sep 18 '22 19:09

Erre Efe