Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1012409 of style

  • Revision slug: Web/SVG/Attribute/style
  • Revision title: style
  • Revision id: 1012409
  • Created:
  • Creator: Tigt
  • Is current revision? Yes
  • Comment

Revision Content

« SVG Attribute reference home

The style attribute specifies style information for its element. It functions identically to the style attribute in HTML.

Usage context

Categories Presentation attribute
Value <style>
Animatable No
Normative document SVG 1.1 (2nd Edition)
<style>
The syntax of style data depends on the style sheet language. By default, the style sheet language is CSS.

Note: In theory, the contentStyleType attribute could be used to specify styling languages other than CSS, like XSL(T). However, this was never implemented satisfactorily in browsers, so do not rely on it.

Example

The following example shows styling of a rectangle with the style attribute using CSS as style sheet language.

<svg viewbox="0 0 1000 500" xmlns="https://www.w3.org/2000/svg">
  <rect height="300" width="600" x="200" y="100" 
     style="fill: red; stroke: blue; stroke-width: 3"/>
</svg>

Elements

The following elements can use the style attribute

  • {{ SVGElement("style") }}

Revision Source

<p>« <a href="/en/SVG/Attribute">SVG Attribute reference home</a></p>

<p><span class="seoSummary">The <strong><code>style</code></strong> attribute specifies <a href="/en-US/docs/Web/CSS">style information</a> for its element. It functions identically to <a href="/en-US/docs/Web/HTML/Global_attributes/style">the <code>style</code> attribute in HTML</a>.</span></p>

<h2 id="Usage_context">Usage context</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="row">Categories</th>
   <td>Presentation attribute</td>
  </tr>
  <tr>
   <th scope="row">Value</th>
   <td>&lt;style&gt;</td>
  </tr>
  <tr>
   <th scope="row">Animatable</th>
   <td>No</td>
  </tr>
  <tr>
   <th scope="row">Normative document</th>
   <td><a class="external" href="https://www.w3.org/TR/SVG/styling.html#StyleAttribute">SVG 1.1 (2nd Edition)</a></td>
  </tr>
 </tbody>
</table>

<dl>
 <dt>&lt;style&gt;</dt>
 <dd>The syntax of style data depends on the style sheet language. By default, the style sheet language is <a href="/en-US/docs/Web/CSS">CSS</a>.</dd>
 <dd>
 <p class="note"><strong>Note:</strong> In theory, <a href="/en-US/docs/Web/SVG/Attribute/contentStyleType">the contentStyleType attribute</a> could be used to specify styling languages other than CSS, like <a href="/en-US/docs/Web/XSLT">XSL(T)</a>. However, this was never implemented satisfactorily in browsers, so do not rely on it.</p>
 </dd>
</dl>

<h2 id="Example">Example</h2>

<p>The following example shows styling of a rectangle with the style attribute using CSS as style sheet language.</p>

<pre class="brush: html">
&lt;svg viewbox="0 0 1000 500" xmlns="https://www.w3.org/2000/svg"&gt;
  &lt;rect height="300" width="600" x="200" y="100" 
     style="fill: red; stroke: blue; stroke-width: 3"/&gt;
&lt;/svg&gt;
</pre>

<h2 id="Elements">Elements</h2>

<p>The following elements can use the <code>style</code> attribute</p>

<ul>
 <li><a href="/en/SVG/Element#Container">Container elements</a> »</li>
 <li><a href="/en/SVG/Element#FilterPrimitive">Filter primitive elements</a> »</li>
 <li><a href="/en/SVG/Element#Gradient">Gradient elements</a> »</li>
 <li><a href="/en/SVG/Element#Graphics">Graphics elements</a> »</li>
 <li><a href="/en/SVG/Element#Structural">Structural elements</a> »</li>
 <li><a href="/en/SVG/Element#TextContent">Text content elements</a> »</li>
 <li>{{ SVGElement("clipPath") }}</li>
 <li>{{ SVGElement("filter") }}</li>
 <li>{{ SVGElement("font") }}</li>
 <li>{{ SVGElement("foreignObject") }}</li>
 <li>{{ SVGElement("glyphRef") }}</li>
 <li>{{ SVGElement("stop") }}</li>
 <li>{{ SVGElement("glyph") }}</li>
</ul>

<h2 id="Related">Related</h2>

<ul>
 <li>{{ SVGElement("style") }}</li>
</ul>
Revert to this revision