Join TalkersCode Now !

Get Latest Tutorials And Links On Web Development
And Get Existing Offers Via Email

Disable Text Selection In WebPage Using CSS.

Friday, Apr 7, 2017

Tags:- CSS HTML


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.


See Demo
Disable Text Selection


To Disable Text Selection it takes only Two steps:-

  1. Make a HTML file and define markup for webpage
  2. 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.

Join Us With Our 21000+ Subscribers And Get Our Latest Tutorials Update Via Email

Are You Starting A New Blog
Do You Want Best Web Hosting?

Try World's Best Web Hosting Provider BlueHost
At Just $3.95/mo

Hurry Up! Limited Time Offer

Yes, I Want To Check Out BlueHost

Check The World's Best SEO And All-In-One Marketing Toolkit
For Digital Marketing Professionals SEMRUSH

Check Out SEMRUSH