Interactive online courses HTML Academy
2026-03-09 10:55 Diff

By default, SVG content with a viewBox is scaled to maintain the aspect ratio, and if the aspect ratios of the sides of the viewport and viewbox do not match, margins will appear around the content:

The preserveAspectRatio property can be used to change this behavior: for example, the value none indicates that the aspect ratio should not be preserved:

<svg viewBox="0 0 237 300" preserveAspectRatio="none"> … </svg>

In this case, the area whose dimensions are set by the viewbox is stretched to fit the entire available viewport space:

preserveAspectRatio is set only using an attribute.