Vector graphics are wonderful ~ they allow for prefect precision and scale without loss of quality. With SVGs now the web – you should definitely spend time to create vector graphics for your sites and understand their use on the web.
The vector pen tool might present a challenge to get to learn with while you are not used to it. But time, patience and practice will pay off. Have a go at completing these tracing templates and you’ll soon get to grips with it :)
↓ download tracing templates
To combine your vector graphics with a bit of coding, let’s take a look at creating and implementing sprite rollovers.
replace the icon for the CTA with your own version – at double its original size.
working with SVG
One of the most exciting developments in regard to web graphics is the possibility of finally using SVG for our vector work. Though you still need to be cautious, consider older browsers and ensure to put in place required fallbacks. There is plenty of documentation out there by now, and you should take time to do some reading and plenty of experimentation and testing before you commit to SVGs for your web project. But it is worth your time and attention – support from browsers is already pretty good for the latest versions :)
In a by-now-old version of our website, we worked on using SVGs with animation, mainly created for this page of our then current site, how we work, as well as our error page. While there are now different and better ways to include SVG on your webpage, the following references we collected at the time will still be useful. We can look at the basic before moving onto more complexities. The following list of references, articles and tools is what we went through when figuring out how to best use SVG, combined with CSS animations.
- SVG – can I use?
- SVG and IMG tag tricks (trialled, tested and implemented on eyedea.eu)
- SVG Editor by Peter Collingridge (used to optimise all SVGs on eyedea.eu)
- SVG Tutorial by Jakob Jenkov
available very cheap as kindle version only, the link above is to the free online version
- Using SVG + SVG Fallbacks by Chris Coyier
- convert SVG to Data URI – online conversion tool: Base64 encoder and decoder by Mobilefish
- filament group: Dingbat Webfonts: Great potential, but we see (and hear) accessibility issues
- Ten reasons we switched from an icon font to SVG, Ian Feather from Lonely Planet
a few notes on what we’ve learnt:
- make sure your vector shape is as clean as possible
(I’m using pathfinders a lot, keeping original shapes – best expanded for lessor points, cleaner shape = less code, less weight)
- always apply transformation to <svg> element, not <g> element
- ideally, place SVG into source code for fewer calls to server
- major differences in SVG rendering between Chrome/Safari/Opera and Firefox – work/test across all to ensure solid display
- check across vector apps for SVG output – compare / always optimise for less code
- keep updating! check for latest developments and test! test! test!
In regards to the different SVG outputs – have a look at the difference between the code from Illustrator (left) and Inkscape (right).
SVG ~ let’s take a look.
This pen icon shown here is the PNG version, shown at it’s original size. At this size, on medium to larger screens this graphic is now scaled and displays at hight quality. Note how badly it pixellates when scaled up on smaller screen sizes (something you will of course always avoid.). This scaling was put in place on purpose – for an easy comparison with the final SVG implementation we will work on now.
Let’s start by opening the SVG in the browser and taking a look at the code. This is the output by Illustrator, before any optimisation of the vectors; code is untouched and as generated via the ‘save as’ command.
Open the file in your favourite vector app and let’s see what could be optimised in terms of the graphic itself. Lastly, use the brilliant SVG Editor by Peter Collingridge to optimise the code – preview / test and see :)
We will use a technique which has been written about by both Chris Coyier and Sara Soueidan – please check the recommended reading links for detailed references.
To display our SVG as part of a webpage – we will first embed the SVG into our HTML page.
<!-- START icon definition --> <svg style="display: none;" version="1.1" xmlns="http://www.w3.org/2000/svg" x="0" y="0" width="72" height="72" viewBox="0 0 72 72" enable-background="new 0 0 72 72" xml:space="preserve"> <symbol> <path id="pen" d="M53.3 56h-7.6l0-4.8 10.8-10.7L35.2 1.3 15.4 41l10.6 10.7L26.1 56h-6.4l0 1h6.4l0 12h1.5l0-12h3.9l0 12h14.4l0-12h7.6L53.3 56zM27.5 56l0-4.9L17.2 40.8 34.5 5.9l0.1 25.9 1.5 0L36 5.9 54.6 40.2 44 50.6v5.4l-13 0V56H27.5z"/> </symbol> </svg> <!-- END icon definition -->
This now defines the embedded SVG as a container for the pen icon. It is hidden and our graphic will now be displayed via
<use> in whichever context required.
<!-- START show icon --> <svg width="72" height="72" viewBox="0 0 72 72" xml:space="preserve"> <use xlink:href="#pen"></use> </svg> <!-- END show icon -->
Once done – we can now proceed to style our icon, work on layout, RWD and all the rest. Here’s a quick demo of the final result – showing off the sharp lines of our SVG by scaling the icon to 100%.
Know your experts: Sara Soueidan
Sara is amazing! You might have come across her work before. Sara is a brilliant front-end developer (and speaker), her expertise includes CSS and Janascript. She has also written many in-depth articles covering some of the complexities and powerful features of SVGs. I was going to give you a list of articles to read, like the brilliant Understanding SVG Coordinate Systems and Transformations (Part 1) – but then realised there are too many :) I recommend that you search Sara’s site for SVG – and absorb them all! (as well as the rest of her work: her now famous CSS reference on codrops is worth bookmarking, if you have not done so already :)
related recommended reading
- Tips for Creating Accessible SVG, Léonie Watson
- Icon System with SVG Sprites, Chris Coyier
- An Overview of SVG Sprite Creation Techniques, Sara Soueidan
Comments are closed.