SVG display: none vs visibility: hidden Explained

While both display: none and visibility: hidden make SVG elements invisible on the screen, they interact differently with the SVG rendering tree, geometry calculations, child inheritance, and pointer events. Understanding these distinctions is crucial when manipulating vector graphics with CSS and JavaScript, especially when calculating dimensions via getBBox() or managing interactive vector states.

Rendering Tree and Bounding Box Calculations

The primary difference lies in how the browser constructs the SVG rendering tree and calculates geometry:

Inheritance and Child Overrides

The two properties handle CSS inheritance differently for nested SVG elements (such as <g> groups):

Pointer Events and Interactivity

Mouse and touch interaction behave differently based on SVG pointer event specifications:

Performance and Use Cases

Use display: none when an SVG asset or path should be fully deactivated, ignored during layout computations, and excluded from assistive technologies to save rendering overhead.

Use visibility: hidden when you need to read layout metrics using JavaScript, create invisible interaction hitboxes, selectively show individual child nodes within a hidden group, or animate visibility transitions smoothly.