![]() |
Disabling text selection in HTML can be useful in scenarios where you want to prevent users from copying text, dragging elements, or accidentally selecting text while interacting with web page elements. These are the following approaches: Using user-select PropertyIn this approach we will use the user-select CSS property. This property is used to control the user’s ability to select text. This is the most straightforward and modern way to disable text selection. Syntax:element { Example: In below example we are using user-select to disable text selection in HTML with CSS.
Output: ![]() Output Using Vendor Prefixes for Cross-Browser CompatibilityTo ensure compatibility across different browsers, it is important to include vendor prefixes for the user-select property. Different browsers might require specific prefixes to support the user-select property. This approach ensures that the text selection behavior is consistent across all major browsers. Syntax:element { Example: To disable text selection on a div element with cross-browser support:
Output: ![]() Output |
Reffered: https://www.geeksforgeeks.org
CSS |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 24 |