Category:SVG simplification by grouping

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Using some care to arrange elements which share attributes may avoid to repeat their definition.

Such a structure collects the most used attributes into a group element (<g …>), and specifies separately the other needed ("inner") attribute values; they may override the inherited ("outer") group attribute values.

<g stroke="#000" stroke-width="3" stroke-linejoin="round" fill="#093">
  <path stroke-width="5" …>

  <g fill="#FFF">
    <path …>
    <path …>
  </g>

  <path stroke="#F00" …>
</g>

It is also possible to set attributes globally with the start tag <svg …> instead of adding a <g> element at the root (example: <svg xmlns=… width="300" height="300" … fill="#FED" stroke="#000" stroke-width="12" stroke-linecap="round" stroke-opacity=".4">).


In general, a list of attributes can be written either

  • stroke="#000" stroke-width="3" stroke-linejoin="round" fill="#093" opacity=".4"

or with the "style=" element

  • style="stroke:#000;stroke-width:3;stroke-linejoin:round;fill:#093;opacity=.4"

It can easily be seen that with the style element the same number of bytes is needed for 4 attributes; less attributes need less bytes without it, more than five need less bytes with it.

Media in category "SVG simplification by grouping"

The following 34 files are in this category, out of 34 total.