Lesson 3
Objective: Learn to draw, position and style circles plus learn the basic SVG style properties.
<circle cx="100"cy="100" r="50"></circle>
<circle> ... </circle> The full rectangle element with open and closing tags.
<circle /> Because this does not contain any content it can also be used as a self-closing element.The circle has three layout attributes you must know and remember:
cx Circle center position on the x-axis
cy Circle center position on the y-axis
r The radius of the circle.
This lesson introduces the three most important style properties in the SVG attribute syntax. You must remember and be able to manipulate these.
stroke="colour" The colour of the line of an object. This can be a named colour, an HTML hex color. Eg: #aabbcc or an RGB colour. Eg: rgb(0,100,150)
stroke-width="2" The width of the line around the object. The default unit is pixels.
fill="colour" The colour that fills an object interior area. It uses the same statements as stroke.
The most powerful style attribute value in SVG is "none". EG:
fill="none"
stroke="none"
There are many other styling attributes that can be applied. These will be handled in a separate lesson. Right now learn and practice the "big three".
This first example uses full SVG attributes to define the colour and stroke of the circle. Note that named colours can be used.
<circle cx="200" cy="200" r="100" stroke="black" stroke-width="5" fill="white"> </circle>
This example uses the style attribute to define the colour and stroke of the circle using CSS-like property values. It also uses self closing /> rather than the full closing element.
<circle cx="200" cy="200" r="100" style="stroke:rgb(0,0,0); stroke-width:5; fill:rgb(255,255,255);" />
Here is the Exercise SVG for those who are too lazy to type the SVG. View Cheat SVG Markup
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.