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?
-
What browser are you in? In my testing I couldn't get a whole div to highlight in Firefox 5, Chrome 12 or IE9. – tw16 Aug 10 '11 at 22:29
7 Answers
The CSS below stops users from being able to select text. Live example: http://jsfiddle.net/hGTwu/20/
/* If you want to implement it in very old browser-versions */
-webkit-user-select: none; /* Chrome/Safari */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* IE10+ */
/* The rule below is not implemented in browsers yet */
-o-user-select: none;
/* The rule below is implemented in most browsers by now */
user-select: none;
To target IE9 downwards and Opera the HTML attribute unselectable
must be used instead:
<div unselectable="on">Test Text</div>
-
that didn't prevent the entire div from being highlighted. I noticed it was only for text. I want to prevent the entire div from being highlighted when double clicking on it. – dave Aug 10 '11 at 22:18
-
@dave: I assumed since the only time double clicking caused highlighting is when there was text in it that is what you meant. No need to downvote. – tw16 Aug 10 '11 at 22:37
-
1Doesn't work in IE or Opera. You need the `unselectable` attribute. There's no `-o-user-select`, by the way. – Tim Down Nov 12 '11 at 15:43
-
note for SASS/SCSS users: you can ```@include user-select(none);``` instead of using raw CSS – hilnius Jul 16 '19 at 16:24
-
Strangely, this caused the divs to become draggable even when `draggable = false`, but only on Firefox. – rovyko Mar 18 '20 at 04:47
-
6Almost a decade has passed, so time for a little update: `user-select: none` should be [pretty well supported by now](https://caniuse.com/user-select-none). – bluenote10 Dec 15 '20 at 21:58
This works for me
html
{
-webkit-tap-highlight-color:transparent;
}

- 10,422
- 29
- 111
- 186

- 995
- 8
- 11
-
1
-
12This will only be relevant for webkit browsers such as Chrome and Safari, and will likely not work in any version of IE or Firefox. – Simon East May 19 '16 at 05:08
I was trying to find a solution to stopping div highlighting in Chrome, and turned to this post. But, unfortunately, none of the answers solved my problem.
After a lot of online research, I found that the fix is something very simple. There is no need for any complex CSS. Just add the following CSS to your web page and you are all set. This works in laptops as well as mobile screens.
div { outline-style:none;}
NOTE: This worked in Chrome Version 44.0.2403.155 m. Also, it is supported in all major browsers of today as explained at this url: https://developer.mozilla.org/en-US/docs/Web/CSS/outline-style
I'm no CSS expert, but I think you can use tw16's answer as long as you expand the number of elements affected. For instance, this prevents highlighting everywhere on my page without affecting any other kind of interactivity:
*, *:before, *:after {
-webkit-user-select: none; /* Chrome/Safari */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* IE10+ */
}
That first line is courtesy of Paul Irish (via http://adamschwartz.co/magic-of-css/chapters/1-the-box/).

- 321
- 6
- 12
-
Do not ever use this CSS when you have a PWA on iOS 13, this completely blocks the keyboard. – Fer Mar 02 '20 at 21:08
Target all div elements:
div::-moz-selection { background:transparent; }
div::selection { background:transparent; }
Target all elements:
::-moz-selection { background:transparent; }
::selection { background:transparent; }

- 12,047
- 89
- 66
disable user selecting:
div {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
set background transparent for selected element:
div::-moz-selection { background:transparent; }
div::selection { background:transparent; }

- 11
- 2
-
3While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – msrd0 Jan 31 '15 at 15:40