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-touch-callout: none;
-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.