Disabling text selection/highlighting with CSS

D

You want to prevent text from being selected/highlighted; whether to prevent copying and pasting or accidental text selection.

To solve this problem you will want to set the user-select CSS property to none.

Disable text selection with user-select

Because each browser is slightly different, the CSS is slightly convoluted because each browser has a slightly different prefixed version of the user-select. Let’s take a look at the example:

In the above example, try selecting the header Title. It is unselectable; however, you can click the button. The user-selectproperty prevents (in this example) all text button being selectable.

If you only wish to apply it to specific elements, you could update the example replacing * with a class name.

About the author

By Jamie

My Books