π What Is pointer-events?
The pointer-events property controls whether an element can respond to mouse, touch, stylus, or click interactions. It determines if the element should receive events like:
- β click
- β hover
- β mousedown / mouseup
- β touchstart / touchend
Note
β Commonly used for overlays, disabled buttons, tooltips, and animations
β Works differently for SVG (extra values exist)
π¦ Syntax
pointer-events syntax
pointer-events: auto | none; /* For HTML elements */
/* SVG supports many more values */| Value | Description |
|---|---|
| auto | Element receives pointer events (default). |
| none | Element ignores pointer events; clicks "pass through" to the element behind it. |
π 1. Disable Clicks on an Element
Disable clicking
button.disabled {
pointer-events: none;
opacity: 0.5;
}Button becomes unclickable but still visible. Unlike disabled attribute, this keeps accessibility states manual.
π 2. Let Events Pass Through an Overlay
Transparent overlay
.overlay {
position: absolute;
inset: 0;
background: rgba(0,0,0,0.3);
pointer-events: none;
}Overlay is visible but does NOT block clicks on underlying elements.
π 3. Temporarily Disable Interactions During Animation
Disable during animation
.modal.animating {
pointer-events: none;
}Ensures users do not interact with elements while they animate in/out.
π 4. Make a Tooltip Ignore Pointer Events
Tooltip example
.tooltip {
pointer-events: none;
}Tooltip becomes βnon-blocking,β preventing accidental hover interruptions.
π 5. Click Through an Empty UI Block
Click through
.ghost-box {
pointer-events: none;
}Useful for decorative elements layered over clickable content.
π 6. Re-enable Events on Children
Children override
.parent {
pointer-events: none;
}
.parent .child {
pointer-events: auto;
}Blocks container interactions but allows specific child elements to remain clickable.
Note
π 7. Full Example β Disabled Button That Still Looks Active
Modern disabled state
.btn {
background: #6200ea;
color: white;
padding: 10px 16px;
border-radius: 6px;
}
.btn.is-disabled {
pointer-events: none;
opacity: 0.4;
}π§ͺ Real-World Use Cases
1οΈβ£ Loading State
Loading screen
body.loading * {
pointer-events: none;
}Prevents the user from interacting while data is loading.
2οΈβ£ Prevent Clicking Behind a Modal Backdrop
Modal backdrop
.backdrop {
pointer-events: auto; /* catches clicks */
}
.backdrop.transparent {
pointer-events: none; /* allows click-through */
}3οΈβ£ Interactive Map with Non-Interactive Labels
Map labels
.label {
pointer-events: none;
}Labels remain visible but never block map interactions.
β οΈ Common Mistakes
- β Expecting pointer-events to disable keyboard input (it doesn't)
- β Using it instead of proper accessibility states for forms
- β Applying pointer-events: none to a parent unintentionally making all children unclickable
- β Forgetting that it affects only pointer devices (not tab navigation)
Note
π₯ Summary
The pointer-events property determines whether an element responds to mouse/touch interactions. It is essential for overlays, disabled states, animations, popups, and layered UI designs.
Learn more βMDN Docs π