How to disable text selection highlighting using CSS?
Making text unselectable is an easy task. All we have to do is to disable the selectivity of the text on our webpage for all the browsers that the webpage is likely to be loaded on. There are some settings/commands used in CSS which are used for enabling/disabling functionalities on specific browsers. Like to disable a certain functionality on our webpage say disabling the selectivity of the text, we will have to disable it for all the available browsers separately else, it will not be applicable on all the browsers.
Let us see what statements do we use for different browsers to disable a selectivity of text.
- Chrome, Opera: -webkit-user-select
- Safari: -webkit-touch-callout
- Mozilla: -moz-user-select
- Internet Explorer: -ms-user-select
Code
<!DOCTYPE html> <html> <head> <title></title> </head> <style type="text/css"> .disable-text{ -webkit-user-select:none; -webkit-touch-callout:none; -moz-user-select:none; -ms-user-select:none; user-select:none; } </style> <body> <p>Unselectable Text</p> <div class="disable-text"> <h1>GeeksForGeeks</h1> </div> <div> <p>Selectable Text</p> <h1>GeeksForGeeks</h1></div> </body> </html> |
Output

Note The text present in the “disable-text” div will not be selected and rest everything is selectable as shown in the output image.
Recommended Posts:
- How to select all text in HTML text input when clicked using JavaScript?
- How to disable a link using only CSS?
- How to disable a CSS :hover effect?
- How to disable tabs in Bootstrap ?
- How to disable resizable property of textarea using CSS?
- How to disable scrolling temporarily using JavaScript?
- How to disable right click on web page using JavaScript ?
- How to disable zoom on a mobile web page using CSS?
- jQuery | disable/enable an input element
- How to disable HTML links using JavaScript / jQuery ?
- How to disable browser Autocomplete on web form field/input tag?
- How to disable dragging an image from an HTML page using JavaScript/jQuery ?
- How to disable paste protection in Mozilla Firefox Developer Console?
- How to enable/disable all input controls inside a form element using jQuery ?
- How to disable scroll to change number in <input type="number"> field using JavaScript/jQuery?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : shubham_singh



