Disable Text Selection In WebPage Using CSS
Last Updated : Jul 1, 2023
In this tutorial we will create how to disable the selection of text using CSS. Whenever the user trying to select the text in your webpage he should not be able to do it.
You may also like disable cut copy and paste using JavaScript.
CHECK OUT THIS TUTORIAL LIVE DEMO →
To Disable Text Selection it takes only Two steps:-
- Make a HTML file and define markup for webpage
- Make a CSS file and define styling to disable the text
Step 1. Make a HTML file and define markup for webpage
We make a HTML file and save it with a name disable.html
<!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href="disable_style.css"> </head> <body> <h1>Disable Text Selection In WebPage Using CSS</h1> <p class="select">Select The Text In This Paragraph This Is Selectable Like Any Other Text</p> <p class="no_select">Try To Select This Text You Are Not Able To Select This Text In Modern Browsers</p> </body> </html>
Step 2. Make a CSS file and define styling to disable the text
We make a CSS file and save it with name disable_style.css.
body { background-color:#EB99FF; font-family:helvetica; text-align:center; margin:0px auto; padding:0px; } h1 { margin-top:100px; color:#424242; font-size:40px; } h1 p { margin:0px; font-size:18px; color:black; text-decoration:underline; } .select { font-size:30px; font-weight:bold; color:#4000FF; } .no_select { font-size:30px; font-weight:bold; color:#4000FF; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; }
In this step we use the user-select property to disable the text selection and also we use cross-browser prefix so that this should work in most of the browser and also with some old browsers.
You may also like enable and disable keyboard keys using JavaScript.
Thats all, this is how to Disable Text Selection In WebPage Using CSS. You can customize this code further as per your requirement. And please feel free to give comments on this tutorial.
I hope this tutorial on disable text selection html css helps you and the steps and method mentioned above are easy to follow and implement.