Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mohamedkhallouq
GitHub Repository: mohamedkhallouq/content
Path: blob/main/files/en-us/web/svg/element/defs/index.md
6580 views
---
title: <defs> slug: Web/SVG/Element/defs page-type: svg-element tags: - SVG - SVG Container browser-compat: svg.elements.defs
---

{{SVGRef}}

The <defs> element is used to store graphical objects that will be used at a later time. Objects created inside a <defs> element are not rendered directly. To display them you have to reference them (with a {{SVGElement("use")}} element for example).

Graphical objects can be referenced from anywhere, however, defining these objects inside of a <defs> element promotes understandability of the SVG content and is beneficial to the overall accessibility of the document.

Example

html, body, svg { height: 100%; }
<svg viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg"> <!-- Some graphical objects to use --> <defs> <circle id="myCircle" cx="0" cy="0" r="5" /> <linearGradient id="myGradient" gradientTransform="rotate(90)"> <stop offset="20%" stop-color="gold" /> <stop offset="90%" stop-color="red" /> </linearGradient> </defs> <!-- using my graphical objects --> <use x="5" y="5" href="#myCircle" fill="url('#myGradient')" /> </svg>

{{EmbedLiveSample('Example', 150, '100%')}}

Attributes

Global attributes

  • Core Attributes

    • : Most notably: {{SVGAttr('id')}} {{SVGAttr('lang')}}

  • Styling Attributes

    • : {{SVGAttr('class')}}, {{SVGAttr('style')}}

  • Event Attributes

  • Presentation Attributes

    • : Most notably: {{SVGAttr('clip-path')}}, {{SVGAttr('clip-rule')}}, {{SVGAttr('color')}}, {{SVGAttr('color-interpolation')}}, {{SVGAttr('color-rendering')}}, {{SVGAttr('cursor')}}, {{SVGAttr('display')}}, {{SVGAttr('fill')}}, {{SVGAttr('fill-opacity')}}, {{SVGAttr('fill-rule')}}, {{SVGAttr('filter')}}, {{SVGAttr('mask')}}, {{SVGAttr('opacity')}}, {{SVGAttr('pointer-events')}}, {{SVGAttr('shape-rendering')}}, {{SVGAttr('stroke')}}, {{SVGAttr('stroke-dasharray')}}, {{SVGAttr('stroke-dashoffset')}}, {{SVGAttr('stroke-linecap')}}, {{SVGAttr('stroke-linejoin')}}, {{SVGAttr('stroke-miterlimit')}}, {{SVGAttr('stroke-opacity')}}, {{SVGAttr('stroke-width')}}, {{SVGAttr("transform")}}, {{SVGAttr('vector-effect')}}, {{SVGAttr('visibility')}}

Usage notes

{{svginfo}}

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}