XML technologies / SVG / Filters, transformations and gradients / Defining shadows and lighting effects with filters / The defs tag in an SVG file
(Excerpt from “Das Einsteigerseminar SVG — Webgrafiken mit XML” by Helma Spona)
The <defs> tag has already appeared several times without explanation. Let us explain it now. In larger or more complex SVG documents using filters, gradients or fill patterns, these must be defined somewhere. That is the purpose of the <defs> section, which should be at the beginning of the SVG file. Define the <defs> tag immediately after the <svg> tag, and place the SVG file’s actual visible contents after the </defs> tag.
This brings us to the properties of the <defs> section. Unlike elements defined directly inside <svg></svg>, elements defined in the <defs> section become visible only when used. A valid <svg> document with a <defs> section could look as follows:
<?xml version="1.0"?>
...
<svg width="7.5cm" height="5cm">
<defs>
<filter>
...
</filter>
<linearGradient>
...
</linearGradient>
<pattern>
...
</pattern>
</defs>
<rect x="1" y="1" width="198" height="118" style="fill:#888888; stroke:blue"/>
<g>
...
</g>
</svg>
Copyright © verlag moderne industrie GmbH 2001
You may print the online version for your private use.
Otherwise, this chapter from “Das Einsteigerseminar SVG — Webgrafiken mit XML” is subject to the same conditions as the bound edition. The work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
verlag moderne industrie GmbH, Justus-von-Liebig-Straße 1, D-86899 Landsberg/Lech, fon ++49 (0) 81 91 / 125 – 0, leserservice(at)mi-verlag.de
back to top