Over a million developers have joined DZone.

Disable Text Highlighting With CSS

Learn how to disable test highlighting using CSS.

· Web Dev Zone

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

In a previous article I wrote about how you can change the browser selection colour when you highlight text in your browser.

All you need to do is use a CSS selector class of ::selection and define the style to use on your text when a visitors tries to highlight the test.

But what if you want to do the opposite and want to disable your visitor from highlighting the text all together?

There is an experimental property called user select which will allow you to define new instructions when the visitor tries to highlight your content. This feature can be a good way of making it harder for people to highlight your content and copy it into their own website.

All you have to do is use this CSS property.

.disable_text_highlighting {
-webkit-user-select: none; /* Webkit */
-moz-user-select: none;    /* Firefox */
-ms-user-select: none;     /* IE 10  */
/* Currently not supported in Opera but will be soon */
-o-user-select: none;
user-select: none;

The values on this property are:

  • Auto - Visitors can select all content in the element.
  • None - Selecting content is disabled.
  • Text - Can only select text content.

Browser Support

This is currently support on webkit, firefox and IE 10. To use the property you need to prefix it with the different browser prefixes but you should also place the non-prefixed version to future proof the property.

View the demo to see what it can do.


Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.

css,html & xhtml,web dev

Published at DZone with permission of Paul Underwood, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}