Home >Web Front-end >HTML Tutorial >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; }
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).
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>
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!