This page illustrates the application of CSS to the specialized language for creating graphics: SVG.

Below you'll create a simple demonstration that runs in your SVG-enabled browser.


Make a new SVG document as a plain text file, doc8.svg. Copy and paste the content from here, making sure that you scroll to get all of it:

<svg width="600px" height="600px" viewBox="-300 -300 600 600"

<title>SVG demonstration</title>
<desc>Mozilla CSS Getting Started - SVG demonstration</desc>

  <g id="segment" class="segment">
    <path class="segment-fill" d="M0,0 v-200 a40,40 0 0,0 -62,10 z"/>
    <path class="segment-edge" d="M0,-200 a40,40 0 0,0 -62,10"/>
  <g id="quadrant">
    <use xlink:href="#segment"/>
    <use xlink:href="#segment" transform="rotate(18)"/>
    <use xlink:href="#segment" transform="rotate(36)"/>
    <use xlink:href="#segment" transform="rotate(54)"/>
    <use xlink:href="#segment" transform="rotate(72)"/>
  <g id="petals">
    <use xlink:href="#quadrant"/>
    <use xlink:href="#quadrant" transform="rotate(90)"/>
    <use xlink:href="#quadrant" transform="rotate(180)"/>
    <use xlink:href="#quadrant" transform="rotate(270)"/>
  <radialGradient id="fade" cx="0" cy="0" r="200"
    <stop id="fade-stop-1" offset="33%"/>
    <stop id="fade-stop-2" offset="95%"/>

<text id="heading" x="-280" y="-270">
  SVG demonstration</text>
<text  id="caption" x="-280" y="-250">
  Move your mouse pointer over the flower.</text>

<g id="flower">
  <circle id="overlay" cx="0" cy="0" r="200"
    stroke="none" fill="url(#fade)"/>
  <use id="outer-petals" xlink:href="#petals"/>
  <use id="inner-petals" xlink:href="#petals"
    transform="rotate(9) scale(0.33)"/>


Make a new CSS file, style8.css. Copy and paste the content from here, making sure that you scroll to get all of it:

/*** SVG demonstration ***/

/* page */
svg {
  background-color: beige;

#heading {
  font-size: 24px;
  font-weight: bold;

#caption {
  font-size: 12px;

/* flower */
#flower:hover {
  cursor: crosshair;

/* gradient */
#fade-stop-1 {
  stop-color: blue;

#fade-stop-2 {
  stop-color: white;

/* outer petals */
#outer-petals {
  opacity: .75;

#outer-petals .segment-fill {
  fill: azure;
  stroke: lightsteelblue;
  stroke-width: 1;

#outer-petals .segment-edge {
  fill: none;
  stroke: deepskyblue;
  stroke-width: 3;

#outer-petals .segment:hover > .segment-fill {
  fill: plum;
  stroke: none;

#outer-petals .segment:hover > .segment-edge {
  stroke: slateblue;

/* inner petals */
#inner-petals .segment-fill {
  fill: yellow;
  stroke: yellow;
  stroke-width: 1;

#inner-petals .segment-edge {
  fill: none;
  stroke: yellowgreen;
  stroke-width: 9;

#inner-petals .segment:hover > .segment-fill {
  fill: darkseagreen;
  stroke: none;

#inner-petals .segment:hover > .segment-edge {
  stroke: green;

Open the document in your SVG-enabled browser. Move your mouse pointer over the graphic to see what happens.


Notes about this demonstration:

  • The SVG document links the stylesheet in the usual way.
  • SVG has its own CSS properties and values. Some of them are similar to CSS properties for HTML.
Change the stylesheet so that the inner petals all turn pink when the mouse pointer is over any one of them, without changing the way the outer petals work.

See a solution to this challenge.

What next?

In this demonstration, your SVG-enabled browser already knows how to display SVG elements. The stylesheet only modifies the display in certain ways. This is also true for HTML and XUL documents. But you can use CSS for general-purpose XML documents, where there is no predefined way to display the elements. The next page demonstrates this: XML data