Languages
[Edit]
EN

CSS - disable elements dragging

9 points
Created by:
Welsh
902

In this short article, we would like to show how to disable elements dragging using pure CSS.

Quick solution:

.element {
    -webkit-user-drag: none;  /* Safari                             */
     -khtml-user-drag: none;  /* Konqueror HTML                     */
       -moz-user-drag: none;  /* Firefox in the past (old versions) */
        -ms-user-drag: none;  /* Internet Explorer (>=10) / Edge    */
         -o-user-drag: none;  /* Opera                              */
            user-drag: none;  /* Currently supported:               */
                              /* Chrome, Opera and Firefox          */
}

 

Practical example

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <style>

    .disable-dragging {
        -webkit-user-drag: none;  /* Safari                             */
         -khtml-user-drag: none;  /* Konqueror HTML                     */
           -moz-user-drag: none;  /* Firefox in the past (old versions) */
            -ms-user-drag: none;  /* Internet Explorer (>=10) / Edge    */
             -o-user-drag: none;  /* Opera                              */
                user-drag: none;  /* Currently supported:               */
                                  /* Chrome, Opera and Firefox          */
    }
    
    img {
        width: 200px;
        height: 200px;
    }

  </style>
</head>
<body>
  <div>
    <div>Dragging disabled:</div>
    <img class="disable-dragging" src="https://dirask.com/static/bucket/1631898942509-VMYrnXyYZv--image.png" />
  </div>
  <br />
  <div>
    <div>Dragging enabled:</div>
    <img src="https://dirask.com/static/bucket/1574890428058-BZOQxN2D3p--image.png" />
  </div>
</body>
</html>

 

See also

  1. CSS - disable text selection

Alternative titles

  1. CSS - prevent element dragging
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join