How to stop highlighting of a div element when double-clicking

dave picture dave · Aug 10, 2011 · Viewed 88k times · Source

I have this div element with a background image and I want to stop highlighting on the div element when double-clicking it. Is there a CSS property for this?

Answer

tw16 picture tw16 · Aug 11, 2011

The CSS below stops users from being able to select text. Live example: http://jsfiddle.net/hGTwu/20/

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

/* Rules below not implemented in browsers yet */
-o-user-select: none;
user-select: none;

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

<div unselectable="on">Test Text</div>