
How to disable text selection highlighting
Edited
How i can disable text selection highlighting
Asked 1/31/2024 8:49:49 PM
1 Answers

1
To disable text selection highlighting on a web page, you can use CSS. Here's a simple CSS rule that can help you achieve this:
body {
-webkit-user-select: none; /* Disable selection highlighting for Chrome, Safari, and newer versions of Opera */
-moz-user-select: none; /* Disable selection highlighting for Firefox */
-ms-user-select: none; /* Disable selection highlighting for Internet Explorer and Edge */
user-select: none; /* Disable selection highlighting for most modern browsers */
}
This CSS rule targets the <body> element of your webpage and sets the user-select property to none, which prevents users from selecting text. The -webkit-, -moz-, and -ms- prefixes are used for better browser compatibility.
You can add this CSS rule to your stylesheet file or include it directly within a <style> tag in the <head> section of your HTML document.
Here's how you can include it within a <style> tag:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Disable Text Selection</title>
<style>
body {
-webkit-user-select: none; /* Disable selection highlighting for Chrome, Safari, and newer versions of Opera */
-moz-user-select: none; /* Disable selection highlighting for Firefox */
-ms-user-select: none; /* Disable selection highlighting for Internet Explorer and Edge */
user-select: none; /* Disable selection highlighting for most modern browsers */
}
</style>
</head>
<body>
<p>This is a paragraph. Text selection highlighting is disabled.</p>
</body>
</html>
By applying this CSS rule, users won't be able to highlight and select text on your webpage using their mouse or keyboard.
Edited
Answered 1/31/2024 8:50:37 PM