Lesson 1
Objective: Understand that SVG is an XML vocabulary and learn the basic SVG setup properties.
To learn how to hand-craft SVG you have to know the syntax and semantics of the SVG XML. XML is constructed like this:
In this example the SVG ELEMENT has three ATTRIBUTES : viewBox="" width="" height="" . Each of these attributes has their value patterns.
The easiest way to learn SVG is to LEARN BY DOING.
That means using the elements, attributes and values over and over again (memorization) while making something real and of value.
SVG is different from most other XML vocabularies in that it has defined:
The elements are relatively straight-forward to learn. The required construction metric attributes for each element are more challenging to memorize.
Practice makes perfect but remember Cheat Sheets are great. This is not an exam. The Infogrid Pacific SVG Cheat Sheets are available below as printable PDFs.
Remember: SVG is an XML Markup Language
SVG is XML so you can't go sloppy on the tagging. You have to remember the basic rules of XML editing:
HTML5 released us from a lot of the XML "exact" tagging rules but SVG doesn't. It is very fussy stuff. One little quote-mark error or closing element error and you will be instantly in XML hell! Be ready for it.
For this reason cut and paste (and attention) is a very good thing.
NOTE: This version of the practice editor does not do any checks on the SVG except nested layout. We will look at introducing syntax checks in a later version. However these are tutorial pages and not production tools so you having to keep focus on SVG XML syntax and well-formedness is a free learning bonus!
This is a getting started basics. Here we are getting started with the absolute minimum requirement.
This is the absolute minimum SVG you need in HTML5. You can then get coding.
<svg> <!-- Your SVG code goes here --> </svg>
This will work but there are practical reasons why this is a little light. So the standard blocks in this tutorial use the following minimum SVG block. (We are not addressing external SVG files at the moment).
<svg viewBox="0, 0, 400, 400" width="400" height="400"> <!-- Your SVG code goes here --> </svg>
UNITS: All units are pixels by default if there is no unit applied. Units that can be used are the same as CSS: em, ex, px, pt, pc, cm, mm, in.
The Infogrid Pacific SVG Primitives use a standard drawing viewBox of 400px X 400px so we are using that as our standard tutorial block. Each of the interactive editable SVG boxes will have the SVG Primitives box sizing by default. You will learn how to change that.
<svg> </svg> The SVG opening and closing elements defines the container any specific SVG drawing.
viewBox="0, 0, 400, 400" This sets the view of the drawing. In this case the view matches the image size. The four numbers give the position of the viewBox. In order these are: "x-start position, y-start position, box-width, box-height". It is optional, but very useful.
width="400" This sets the width of the drawing on the page in pixels. (It is optional).
height="400" This sets the height of the drawing on the page in pixels. (It is optional).
There is a circle and lines in the SVG at this stage. Ignore these are we are exploring the SVG size and view setup properties here.
You learned the basic HTML5 SVG setup requirements.
Understood the three main SVG attributes viewBox, width and height.
Learned how changing the values of those SVG attributes gives a different presentation of the image in the HTML browser context.
Here are our standard SVG Cheatsheets you can download, print out and have ready when needed. There is also a text file containing annotated quickstarts for all major shapes and techniques.
SVG Editor. Access a full SVG Editor online at any time.