SVG pointer-events: visiblePainted vs all

The pointer-events property in SVG specifies under what circumstances a graphical element can become the target of pointer events, such as mouse clicks, hovers, or touch interactions. The key difference between visiblePainted and all lies in how they handle element visibility and whether the interior (fill) and outline (stroke) of an element must be painted to detect interactions. Understanding these differences allows developers to build precise click targets and invisible interactive zones within SVG graphics.

What is visiblePainted?

visiblePainted is the standard default value for most SVG elements. Under this setting, an element only captures pointer events if it meets strict rendering and visibility criteria:

In short, visiblePainted ensures that users can only interact with pixels that are visibly rendered on the screen.

What is all?

The all value ignores rendering states, visibility settings, and paint values entirely. It makes the entire geometric area of an SVG element interactive.

This makes all particularly useful for creating invisible hit areas, larger tap targets on mobile devices, or hotspot overlays over complex backgrounds.

Key Differences Summary

Feature visiblePainted (Default) all
Responds when visibility: hidden No Yes
Responds when fill="none" No (passes through) Yes (captures interior)
Responds when stroke="none" No (passes through) Yes (captures boundary)
Primary Use Case Standard UI interaction on visible shapes Invisible hitboxes, expanded click targets

Practical Example

Consider a transparent circle overlay intended to act as a button:

<circle cx="50" cy="50" r="40" fill="none" stroke="none" pointer-events="visiblePainted" />

With pointer-events="visiblePainted", clicking this circle does nothing because neither the fill nor the stroke is painted.

<circle cx="50" cy="50" r="40" fill="none" stroke="none" pointer-events="all" />

With pointer-events="all", the entire 40px radius area registers clicks, providing a fully functional invisible hit target without requiring an opacity hack (like opacity="0" with a solid fill).