SVG Width and Height 100 Percent Explained

Setting width="100%" and height="100%" on a root SVG element instructs the graphic to expand and completely fill the dimensions of its parent container. While this enables fluid responsiveness, the final visual behavior depends heavily on the presence of the viewBox attribute, the default preserveAspectRatio rules, and the layout constraints of the wrapping HTML element.

Sizing Relative to the Parent Container

When an SVG has percentage-based dimensions, it treats its immediate parent element as the reference frame:

The Critical Role of the viewBox

The presence of a viewBox determines how the internal artwork scales within the 100% boundaries:

Aspect Ratio and Letterboxing

By default, SVG elements have an implicit preserveAspectRatio="xMidYMid meet" rule. When width="100%" and height="100%" force the SVG into a container with a different aspect ratio than its viewBox:

CSS Precedence and Defaults

Attributes defined directly on the SVG element act as presentational attributes. If external CSS specifies different dimensions (such as svg { width: 50%; }), the CSS rules will override the inline width="100%" and height="100%" declarations. However, leaving the 100% attributes on the root element provides a reliable fallback for environments where external stylesheets fail to load or are unsupported.