How to prevent text selection in html


Its necessary to prevent text selection when the text is ui feature, to make the webpage more professional.

We can prevent the text from selecting by using this in css

user-select: none;

You cannot select this text

You can select this text

example code

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
    <p style="user-select: none;">You cannot select this text</p>
    <p>You can select this text</p>
</body>
</html>

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *