Q&A

Q1:Do I need to include a viewBox attribute on every svg element?
A1: No. The viewBox is a special attribute used when you specifically need to distort the viewport of your content. In most cases, you will never need to deal with a viewBox attribute. Keep in mind, however, that most SVG WYSIWYG editors (such as Adobe Illustrator) will export a viewBox setting that does nothing to your viewport. Unless you need to edit those settings to distort your viewport, you can just delete this attribute and its values.
Q2:When using percentages, do both width and height need to be percentage-based?
A2: No. Just as you can specify varying units for the width and height attributes (such as <rect width="50px" height="3in"/>), you can specify only one dimension ...

Get Sams Teach Yourself SVG in 24 Hours now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.