SVG is essentially to graphics what HTML is to text
viewBox="0 0 6 6"
<svg viewBox="0 0 100 100">
<line x1="0" y1="80" x2="100" y2="20" stroke="black" />
</svg>
<svg viewBox="0 0 100 100">
<circle cx="50" cy="50" r="50"/>
</svg>
<svg viewBox="0 0 220 100">
<rect width="100" height="100" />
<rect x="120" width="100" height="100" rx="15" />
</svg>
<svg viewBox="0 0 200 100">
<polyline points="100,100 150,25 150,75 200,0" fill="none" stroke="black" />
</svg>
<svg viewBox="0 0 200 100">
<polygon points="0,100 50,25 50,75 100,0" />
</svg>
<svg viewBox="0 0 100 100">
<line x1="0" y1="0" x2="50" y2="50" />
<line x1="0" y1="100" x2="50" y2="50" />
</svg>
<svg viewBox="0 0 100 100">
<polyline points="0,0 50,50 0,100" />
</svg>
<svg viewBox="0 0 100 100">
<path d="M0 0 L50 50 L0 100" />
</svg>
.icon {
width: 3em;
height: 3em;
background: lightgrey;
border-radius: 50%;
padding: .75rem;
circle, line, path, polyline {
fill: transparent;
stroke: black;
stroke-width: 2px;
stroke-linecap: round;
vector-effect: non-scaling-stroke;
}
}
<svg viewBox="0 0 100 100" class="icon">
</svg>
<img src="icon-close.svg" alt="Close" class="icon" />
<svg viewBox="0 0 100 100" class="icon">
<path d="M25,25 L75,75 M75,25 L25,75" />
</svg>
<svg aria-hidden="true"
style="position: absolute; width: 0; height: 0; overflow: hidden"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<symbol id="icon-close" viewBox="0 0 100 100">
<title>Close</title>
<path d="M25,25 L75,75 M75,25 L25,75" />
</symbol>
<symbol id="icon-search" viewBox="0 0 100 100">
... etc.
</symbol>
</defs>
</svg>
<svg class="icon">
<use xlink:href="spritemap.svg#icon-close"></use>
</svg>
.icon {
background-image: url('check.svg');
background-position: 100% 50%;
background-repeat: no-repeat;
background-size: 2rem;
}
.icon {
background-color: tomato;
mask-image: url('check.svg');
mask-position: 100% 50%;
mask-repeat: no-repeat;
mask-size: 2rem;
}
Sketch-output sucks
Try out SVG OMG
Then code it using <line>
Then code it with <path>
SvgSpritemapWebpackPlugin
plugins: [
new SvgSpritemapWebpackPlugin('./src/sprites/*.svg', {
output: {
filename: 'spritemap.svg',
svgo: true
},
sprite: {
prefix: 'sprite-'
},
styles: {
filename: '~sprites.scss'
}
}) ...
@import '~svg-spritemap-webpack-plugin/sprites.scss';
.example {
// Using the included .sprite() mixin
.sprite(@sprite-phone);
// Using the SVG variable directly
background-image: url(@sprite-phone);
}
<svg>
<use xlink:href="/path/to/spritemap.svg#sprite-phone"></use>
</svg>
It's not HTML, so:
document.createElementNS("http://www.w3.org/2000/svg", 'svg');