Skip to content
tezvyn:

pointer-events: Making Elements Click-Through

Source: developer.mozilla.orgEasyHow cards are made

pointer-events: Making Elements Click-Through

The pointer-events property makes elements invisible to clicks and hovers, letting events pass through to what's underneath. Use it for decorative overlays on clickable content or to temporarily disable buttons.

Why it exists

Sometimes you need to visually layer elements in a way that conflicts with the desired user interaction. You might have a decorative overlay that covers a button, but you still want the button to be clickable. pointer-events solves this by decoupling an element's visual rendering from its event targeting.

The mental model

Think of pointer-events: none as making an element a ghost. It's visually there, but your mouse cursor passes right through it as if it doesn't exist, interacting with whatever is behind it. The default, pointer-events: auto, means the element behaves normally, blocking clicks from reaching elements below it.

How it works

The pointer-events property is specified with a keyword. For standard HTML elements, the two most important values are auto and none. auto is the default, where the element can be a target for pointer events like clicks and hovers. none makes the element non-reactive to the pointer; the browser will not consider it a target for hit-testing, and any pointer action will "fall through" to the next element down in the z-index stack. While many other values exist, they are primarily for use with SVG graphics to control interaction with an element's fill, stroke, or bounding box.

When to use it

Use pointer-events: none to create non-interactive UI elements that must sit on top of other content, such as a decorative gradient overlay on an image that is also a link. It's also a common way to temporarily disable an element, like a form button during submission, without using the disabled attribute, which has its own styles and behaviors.

When not to use it

Do not rely on pointer-events: none for accessibility. Screen readers and keyboard navigation are not affected by this property. If an element should be truly non-interactive for all users, use the disabled attribute on form controls or aria-hidden="true" for other elements. Also, be aware that children of an element with pointer-events: none can still be made interactive if their own pointer-events property is explicitly set back to auto.

One canonical example

Imagine a with a background image that contains a link ( tag) inside it. If you place another on top as a semi-transparent color overlay, that overlay will block clicks on the link. By setting pointer-events: none; on the overlay , you allow the user to click through the overlay and interact with the link underneath as intended.

Interview question

For which purpose is pointer-events: none most appropriately used on a CSS overlay?

  • a.To ensure the overlay is ignored by accessibility tools like screen readers.
  • b.To hide the overlay from view while keeping its content accessible.
  • c.To make the overlay and its children completely unresponsive to all user input, including keyboard.
  • d.To prevent the overlay from receiving pointer events, allowing interaction with elements beneath it.Correct
Why?

The correct answer (D) describes the core function of pointer-events: none, which is to make an element a 'ghost' for pointer interactions. Option C is incorrect because this property only affects pointer events, not keyboard navigation or accessibility tools, and children can override it.

Just read this? Test yourself on what you have been reading.

Read the original → developer.mozilla.org

You just looked this up. Could you explain it out loud?

That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on css — each one lists the topics its interview covers.

See open roles