In HTML, method to prevent image from being draggable or selectable without using JS

PHPz
Release: 2023-09-03 08:09:06
forward
1263 people have browsed it

In HTML, method to prevent image from being draggable or selectable without using JS

Add the following code snippet to the image properties and prevent the image from being dragged and selected.

img {  
   user-drag: none;  
   user-select: none;
   -moz-user-select: none;
   -webkit-user-drag: none;
   -webkit-user-select: none;
   -ms-user-select: none;
}
Copy after login

When you double-click the text or image, it will be highlighted (selected). User selection attributes can be used to prevent this. By setting this property to none we can prevent the image from being selected (highlighted).

Example

You can try running the following code to prevent the image from being selected -

<!DOCTYPE html>
<html>
   <head>
      <style>
         img {
            -drag: none;
            user-select: none;
            -moz-user-select: none;
            -webkit-user-drag: none;
            -webkit-user-select: none;
            -ms-user-select: none;
         }
      </style>
   </head>
   <body>
      <img src = "https://www.tutorialspoint.com/images/python3.png" alt = "Python" width = "62" height = "62">
   </body>
</html>
Copy after login

The above is the detailed content of In HTML, method to prevent image from being draggable or selectable without using JS. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!