A.5 Layers and Groups

After the metadata element, the actual visible content of the SVG document starts. As you may have guessed, each document object corresponds to an SVG element. Moreover, the order of the elements in the file corresponds to the order in which objects are visually stacked on the canvas (4.3 Z-Order): Elements closer to the end of the file appear atop those nearer the beginning.

When you group several elements together (4.5 Groups), they are placed inside a g element. For example, here’s a group that contains a rectangle and a text object:

<g id="g2893">
  <rect id="rect2310"
        y="350"
        x="100"
        width="300"
        height="150"
        style="opacity:1;fill:#ff0000;stroke:#000000;stroke-width:1px;" />
  <text id="text2889"
        y="400"
        x="200"
        style="font-size:40px;font-style:normal;font-weight:normal;fill:#000000;
               stroke:none;font-family:Bitstream Vera Sans"
        xml:space="preserve">Text in rectangle</text>
</g>

Besides groups, another way to organize your objects is by using layers (4.6 Layers). SVG does not have a special element type for layers; instead, Inkscape just uses an SVG g element, adding a special attribute so it knows to treat the group as a layer when the file is edited.

<g inkscape:groupmode="layer"
   inkscape:label="Layer 1"
   id="layer1">
  ...contents of the layer...
</g>

Since layers are thus a special case of groups, it is easy to understand how Inkscape can “enter a group,” treating it temporarily as a layer (4.6.1 Layer Hierarchy). It also becomes clear why, upon importing Inkscape’s SVG file into another vector editor (such as Adobe Illustrator), you usually lose layers but your objects get additional layers of grouping: The other editor simply does not know about Inkscape’s convention of using some g elements as layers and treats all the layers as regular groups.

Inside layers and groups, other SVG elements represent the actual objects of your drawing. See http://w3.org/TR/SVG11/eltindex.html for a complete list of elements in SVG 1.1, but note that not all of them are supported by Inkscape yet.