O'Reilly logo

Sams Teach Yourself SVG in 24 Hours by Micah Laaker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required