shape-rendering=crispEdges
to disable browser anti-aliasing.Here’s the simplest SVG, a box
1<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
2 <rect width="100" height="100" fill="lightseagreen"/>
3</svg>
height
and width
values are auto
which is treated as 100%
. If you don’t specifically give height
and width
values to the SVG, it’ll assume 100%. This gives you a responsive SVG which will take up entire available space.viewBox
is 0 0 32 32
. If it’s in a 64px container element, the SVG will be 64px.viewBox
value does not have to match the height/width value. they don’t have to be the same SVGviewBox = <min-x> <min-y> <width> <height>
1<!-- RESPONSIVE SVG -->
2<svg viewBox="0 0 460 100" xmlns="http://www.w3.org/2000/svg">
3 <rect width="100" height="100" fill="lightseagreen"/>
4 <rect x="120" width="100" height="100" rx="15" fill="salmon"/>
5 <rect x="240" width="100" height="100" rx="15" fill="plum"/>
6 <rect x="360" width="100" height="100" rx="15" fill="palevioletred"/>
7</svg>
1<!-- FIXED SIZE SVG -->
2<svg viewBox="0 0 460 100" width="460" height="100" xmlns="http://www.w3.org/2000/svg">
3 <rect width="100" height="100" fill="lightseagreen"/>
4 <rect x="120" width="100" height="100" rx="15" fill="salmon"/>
5 <rect x="240" width="100" height="100" rx="15" fill="plum"/>
6 <rect x="360" width="100" height="100" rx="15" fill="palevioletred"/>
7</svg>
1<!-- CONATINED SVG -->
2<div style="width: 64px; height: 64px">
3 <svg viewBox="0 0 460 100" xmlns="http://www.w3.org/2000/svg">
4 <!-- Simple rectangle -->
5 <rect width="100" height="100" fill="lightseagreen"/>
6
7 <!-- Rounded corner rectangle -->
8 <rect x="120" width="100" height="100" rx="15" fill="salmon"/>
9
10 <!-- Rounded corner rectangle -->
11 <rect x="240" width="100" height="100" rx="15" fill="plum"/>
12
13 <!-- Rounded corner rectangle -->
14 <rect x="360" width="100" height="100" rx="15" fill="palevioletred"/>
15 </svg>
16</div>