A proposed CSS pseudo-class `:drag` would enable styling elements during drag interactions without JavaScript. Currently, developers must use the HTML Drag and Drop API with JavaScript event listeners and class toggling to achieve this effect. The proposal would simplify the process by allowing direct CSS styling when elements are being dragged. The author also suggests a `::drag-image` pseudo-element for customizing the preview image shown during dragging, which currently requires JavaScript's `dataTransfer.setDragImage()` method. Both proposals aim to reduce JavaScript dependencies and improve performance for common drag-and-drop UI patterns.

4m read timeFrom css-tricks.com
Post cover image
Table of contents
How about the preview image?Thoughts?
3 Comments

Sort: