--- title: symbol slug: Web/SVG/Element/symbol tags: - SVG - SVG容器 - 元素 - 需要示例 translation_of: Web/SVG/Element/symbol ---
{{SVGRef}}

symbol元素用来定义一个图形模板对象,它可以用一个{{ SVGElement("use") }}元素实例化。symbol元素对图形的作用是在同一文档中多次使用,添加结构和语义。结构丰富的文档可以更生动地呈现出来,类似讲演稿或盲文,从而提升了可访问性。注意,一个symbol元素本身是不呈现的。只有symbol元素的实例(亦即,一个引用了symbol的 {{ SVGElement("use") }}元素)才能呈现。

用法

{{svginfo}}

示例

<svg>
<!-- symbol definition  NEVER draw -->
<symbol id="sym01" viewBox="0 0 150 110">
  <circle cx="50" cy="50" r="40" stroke-width="8" stroke="red" fill="red"/>
  <circle cx="90" cy="60" r="40" stroke-width="8" stroke="green" fill="white"/>
</symbol>

<!-- actual drawing by "use" element -->
<use xlink:href="#sym01"
     x="0" y="0" width="100" height="50"/>
<use xlink:href="#sym01"
     x="0" y="50" width="75" height="38"/>
<use xlink:href="#sym01"
     x="0" y="100" width="50" height="25"/>
</svg>

{{EmbedLiveSample("Example", 150, 110)}}

属性

全局属性

专有属性

DOM 接口

该元素实现了SVGSymbolElement接口。

浏览器兼容性

{{Compat("svg.elements.symbol")}}

另见