Sara Soueidan PRO
Freelance front-end web developer, writer, and speaker.
OH: “People end up making graphics with CSS [instead of SVG], because for many use cases, it offers them more flexibility. Which is absurd.”
— fantasai (@fantasai)
January 31, 2015
<svg viewBox="0 0 32 32"> <path d="M23.6 2c-3.363 0-6.258 2.736-7.599 5.594-1.342-2.858-4.237-5.594-7.601-5.594-4.637 0-8.4 3.764-8.4 8.401 0 9.433 9.516 11.906 16.001 21.232 6.13-9.268 15.999-12.1 15.999-21.232 0-4.637-3.763-8.401-8.4-8.401z" fill="#444444"></path> </svg>
<svg viewBox="0 0 32 32"> <circle cx=".." cy=".." r=".." fill=".."></circle> </svg>
<svg viewBox="0 0 32 32"> <rect x=".." y=".." width=".." height=".." fill=".."></rect> </svg>
AND MUCH MUCH MORE.
FAKE CONTENT
REAL CONTENT
Example: Circular Menus
More expressive feedback & interactions
input[type="checkbox"] { display: none; } input[type="checkbox"] + label { display: inline-block; padding-left: 1em; background: url(checkbox_states_spritesheet.png) left center no-repeat; cursor:pointer; } input[type="checkbox"]:checked + label { background: url(check_radio_sheet.png) -1em center no-repeat; }
<input type="checkbox" id="option"/>
<label for="option"> Click me
<svg viewBox="0 0 60 40" xmlns="http://www.w3.org/2000/svg"><path d="M21,2 C13.4580219,4.16027394 1.62349378,18.3117469 3,19 ..." stroke="orange" stroke-width="4" fill="none" stroke-dasharray="270" stroke-dashoffset="-270"></path></svg>
</label>
input[type="checkbox"]:checked ~ label svg path {
stroke-dashoffset: 0;
}
Example: Textured and Animated Text
.hide-text {
text-indent: 100%;
white-space: nowrap;
overflow: hidden;
background-image: url(...);
}
The Kellum Method:
Other Image Replacement Techniques:
h1 { background: url(../img/kitchen.jpg) no-repeat center center; background-size: cover; color: #fff; text-align: center; padding: 2em; /* -webkit-background-clip clips the background of the element to the text */ -webkit-background-clip: text;
/* overrides the white text color in webkit browsers */ -webkit-text-fill-color: transparent; }
Text with fill
Filled Text (Background clipped) EXAMPLE
Textured text
h1 { font: 35em/100% "Oswald", sans-serif; margin: 0 auto; padding: 0; text-align: center; color: #fff; -webkit-mask-image: url(../img/splatter-mask_1.png); mask-image: url(../img/splatter-mask_1.png); }
Textured Text (Mask image)
Text with fill
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1000" height="400">
<!-- add title for accessibility -->
<title>Applying a gradient background to text in SVG</title> -->
<!-- SOurce: http://lea.verou.me/2012/05/text-masking-the-standards-way/ -->
<defs>
<linearGradient id="filler" x="0%" y="100%">
<stop stop-color="olivedrab" offset="0%"></stop>
<stop stop-color="peru" offset="20%"></stop>
<stop stop-color="goldenrod" offset="40%"></stop>
<stop stop-color="firebrick" offset="60%"></stop>
<stop stop-color="thistle" offset="80%"></stop>
<stop stop-color="sandybrown" offset="100%"></stop>
</linearGradient>
</defs>
<text x="100" y="70%" font-size="205" fill="url(#filler)"> GRADIENT</text>
</svg>
Text with fill EXAMPLE
<svg viewBox="0 0 700 400">
<defs> <mask id="mask"> <image width="1200px" height="1200px" xlink:href="img/splatter-mask_luminance.png" preserveAspectRatio="none"/> </mask> </defs> <text x="50" y="70%" font-size="168" fill="white" mask="url(#mask)">WATERCOLOR</text>
</svg>
Textured text
Textured text EXAMPLE
You can pass the output of one filters an input to another filter..
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"> <defs> <filter id="goo"> <feGaussianBlur in="SourceGraphic" stdDeviation="10" result="blur" /> <feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 19 -9" result="goo" /> <feComposite in="SourceGraphic" in2="goo" operator="atop"/> </filter> </defs> </svg>
http://codepen.io/lbebber/
@lucasbebber
<svg viewBox="0 0 1000 300" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <defs> <path id="MyPath" d="M 100 200 C 200 100 300 0 400 100 C 500 200 600 300 700 200 C 800 100 900 100 900 100" /> </defs> <use xlink:href="#MyPath" fill="none" stroke="red" /> <text font-family="Verdana" font-size="42.5"> <textPath xlink:href="#MyPath"> We go up, then we go down, then up again </textPath> </text> </svg>
<svg viewBox="0 0 1000 300" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <defs> <path id="MyPath" d="M 100 200 C 200 100 300 0 400 100 C 500 200 600 300 700 200 C 800 100 900 100 900 100" /> </defs> <use xlink:href="#MyPath" fill="none" stroke="red" /> <text font-family="Verdana" font-size="42.5"> <textPath xlink:href="#MyPath"> We go up, then we go down, then up again <animate attributeName="startOffset" values="0;1" dur="5s" repeatCount="indefinite" keyTimes="0;1" /> </textPath> </text> </svg>
<animateMotion
xlink:href="#circle"
dur="1s"
begin="click"
fill="freeze"
path="..." />
<animateMotion xlink:href="#circle" dur="1s" begin="click" fill="freeze"> <mpath xlink:href="#motionPath" /> </animateMotion>
OR
We don't download fonts; icons are what svg is for.
Bruce 'Captain Wonderful' of Opera—a.k.a Bruce Lawson
sarasoueidan.com
@SaraSoueidan
By Sara Soueidan
Freelance front-end web developer, writer, and speaker.