1.3.1. Simple SVG instance ¶
SVG files are recommended to use
.svg
(all lowercase) as an extension for such files.
A simple example of SVG graphics:
test.svg
File
<svg version="1.1"
baseProfile="full"
width="300" height="200"
xmlns="http://www.w3.org/2000/svg">
<rect width="100%" height="100%" stroke="red" stroke-width="4"
fill="yellow" />
<circle cx="150" cy="100" r="80" fill="green" />
<text x="150" y="115" font-size="16" text-anchor="middle"
fill="white">RUNOOB SVG TEST</text>
</svg>
SVG code parsing:
SVG code to
<svg>
element start, including the open tag
<svg>
and close the label
</svg>
. This is the root element.
width
and
height
property to set the width and height of this SVG document.
version
property to define the version of SVG used
xmlns
property defines the SVG namespace.
SVG’s
<rect>
used to create a rectangle, through the
fill
set the background color to yellow.
SVG’s
<circle>
used to create a circle. The cx and cy properties definethe x and y coordinates of the center of the circle. If you omit these two attributes, the dot is set to (0,0), and the r attribute defines the radius of the circle. A green circle with a radius of 80px
<circle>
draw in the right center of the red rectangle (offset 150px to the right, offset 115px down).
stroke
and
stroke-width
property controls how the outline of the shape is displayed. We set the outline of the circle to 4px wide and red border.
fill
property to set the color within the shape. We set the fill color to red.
Close the label
</svg>
the function is to turn off
SVG
elements and the document itself.
Note: all open tags must be closed!