CSS Pointer Events
In this page:
selector {
pointer-events: auto | none;
}
The none Value
pointer-events: none removes an element from the pointer interaction tree entirely, so clicks and hovers pass through it to whatever element is stacked beneath.
- Use pointer-events: none on decorative icons placed inside buttons so hovering the icon still correctly registers as hovering the button.
- Accepted values:
- auto — normal pointer behavior (default)
- none — element ignores pointer events and lets them pass through
- SVG-only values — visiblePainted, fill, stroke, all
- inherit | initial | unset | revert — CSS-wide keywords accepted by every property
Example: The none Value
<style>
.icon {
pointer-events: none;
}
</style>
<button><span class="icon">🔍</span> Search</button>
The auto Value
pointer-events: auto restores standard interactive behavior and is the default for most elements, but it becomes especially useful for re-enabling one child inside a parent that has pointer-events: none applied.
- Use pointer-events: auto on a specific close button inside an otherwise non-interactive disabled overlay to keep just that one action available.
- Accepted values:
- auto — normal mouse and touch behavior (initial value)
- none — the element ignores pointer events
- visiblePainted | visibleFill | visibleStroke | visible | painted | fill | stroke | all — SVG-specific values
- inherit | initial | unset | revert — CSS-wide keywords accepted by every property
Example: The auto Value
<style>
.disabled-overlay {
pointer-events: none;
background: rgba(0,0,0,0.4);
padding: 20px;
}
.close-btn {
pointer-events: auto;
}
</style>
<div class="disabled-overlay">
<button class="close-btn">Close (still works)</button>
</div>
Disabling Clicks on an Element
pointer-events: none is a lightweight way to visually disable an interactive-looking element without removing it from the layout or hiding it, unlike the disabled attribute which only applies to form controls.
- For custom clickable divs acting as buttons, combine pointer-events: none with reduced opacity and cursor: not-allowed for a fully disabled appearance.
- Accepted values:
- auto — normal mouse and touch behavior (initial value)
- none — the element ignores pointer events
- visiblePainted | visibleFill | visibleStroke | visible | painted | fill | stroke | all — SVG-specific values
- inherit | initial | unset | revert — CSS-wide keywords accepted by every property
Example: Disabling Clicks on an Element
<style>
.fake-disabled {
pointer-events: none;
opacity: 0.5;
cursor: not-allowed;
background: lightgray;
padding: 12px;
}
</style>
<div class="fake-disabled">Visually disabled without the disabled attribute</div>
Overlay Elements
Full page overlays, such as modal backdrops or loading screens, often need to block interaction with everything beneath them while remaining clickable themselves, the opposite use case from the icon pattern.
Example: Overlay Elements
<style>
.backdrop {
position: fixed;
inset: 0;
background: rgba(0,0,0,0.5);
color: white;
pointer-events: auto;
}
</style>
<div class="backdrop">Clickable, so clicking it can close the modal</div>
pointer-events on SVG
pointer-events was originally an SVG-only property with additional values like visiblePainted and all, controlling whether fill, stroke, or bounding box areas respond to pointer interaction.
Example: pointer-events on SVG
<svg width="100" height="100">
<circle cx="50" cy="50" r="40" fill="lightblue" stroke="steelblue" stroke-width="2" pointer-events="all"></circle>
</svg>
- Setting pointer-events: none on an entire disabled form without realizing it also blocks screen reader interaction cues, always pair it with aria-disabled.
- Forgetting that a child element can restore pointer-events: auto to become clickable again even if its parent set pointer-events: none.
- Using pointer-events: none as the only way to disable a button, which does not prevent the button from being focused and activated by keyboard.
- pointer-events: none makes an element invisible to mouse and pointer interactions while keeping it visually present.
- pointer-events: auto is the default and restores normal interactivity, useful for re-enabling a specific child inside a disabled parent.
- pointer-events: all forces an SVG element to always respond to pointer events regardless of its fill or stroke visibility.
pointer-events is supported on all elements in every modern browser; support on non-SVG HTML elements arrived slightly later than SVG support but is now universal.
Chapter Quiz — Complete all 22 topics to unlock
0/22 topics done
Complete these topics first:
- CSS Combinators
- CSS Pseudo-classes
- CSS Pseudo-elements
- CSS Opacity
- CSS Navigation Bar
- CSS Vertical Navbar
- CSS Horizontal Navbar
- CSS Dropdowns
- CSS Advanced Dropdowns
- CSS Image Gallery
- CSS Image Sprites
- CSS Attribute Selectors
- CSS Forms
- CSS Counters
- CSS Specificity
- CSS Specificity Hierarchy
- CSS Variables
- CSS !important
- CSS Box Sizing
- CSS Media Queries
- CSS Pointer Events
- CSS Outline