How to Disable Text Selection Highlighting Using CSS

Disable Text Selection Highlighting

You can use CSS for many things and one the uses is to disable text selection in your text, tabs, buttons, and more.

This can be done using the user-select selector which is supported in all major web browsers except for Internet Explorer 9 and earlier versions. We will highlight a JavaScript solution that can be used for older web browsers.

The user-select syntax and available variations:

Usage in HTML:

The following JavaScript solution can be used in Internet Explorer 9 and older browser versions to disable text selection highlighting:

onSelectStart="return false;"

Usage in HTML:

Bonus Tip to Disable Text Selection Highlighting

You may also want to prevent the context menu from appearing on elements like buttons that have their selection prevented. To do that, add this code to the entire page, or just those button elements:

or:

Read Also  Here's How to Redirect Your Old Website to a New One