
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
Preventing an image from being draggable or selectable in HTML without using JS
Add the following code snippet to image properties, and prevent images 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; }
On double click on a text or image, it is highlighted (selected). The user select property can be used to prevent this. By setting this property to none, we can prevent our image from being selected (highlighted).
Example
You can try to run 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>
- Related Articles
- How to set whether an element is draggable or not in HTML?
- HTML draggable Attribute
- Create a selectable list in HTML
- Creating a Map in React JS without using third-party API
- How to use external “.js” files in an HTML file?
- JS Geolocation but without prompting possible?
- Creating a PDF in React JS using plain CSS and HTML
- How to set caption for an image using HTML?
- How to upload an image using HTML and JavaScript in Firebase?
- How to pick an image from an image gallery on Android using Kotlin?
- Display or over image on :hover in HTML
- How to Add an Image in Text Background using HTML and CSS?
- Create JS Radial gradient with matrix in HTML
- Display an Icon from Image Sprite using CSS
- How to display an image in HTML?

Advertisements