SVG Icon Sprite - Web Component

« Back to overview

Scaling and sizing recommendations

Scaling (using viewBox)

Scaling via viewBox is not consistent across browsers. The pattern depends on your SVG source file, whether it already contains a viewBox or not. The following example SVGs with an original size of 100x100px are scaled down by 50%.

<!-- SVG source lacks a viewBox -->
<svg-icon
    src="assets/sprites/sprite.svg#star_100x100"
    width="100px"
    viewBox="-50 -50 200 200">
</svg-icon>

<!-- SVG source contains a viewBox -->
<svg-icon
    src="assets/sprites/sprite.svg#star_100x100_viewbox"
    width="50px"
    viewBox="0 0 100 100">
</svg-icon>