Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>Three Ways to Animate SVG</h1>

<p>This robot dude is being animated in three differnet ways.</p>

<svg version="1.1" id="robot" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
	 viewBox="0 0 127.9 178.4" enable-background="new 0 0 127.9 178.4" xml:space="preserve">
<path id="left-leg" fill="#424143" d="M37.6,138.8c0-3.2-2-5.8-4.9-6.8c2.8-1,4.9-3.6,4.9-6.8c0-4-3.2-7.2-7.2-7.2h-4.6
	c-4,0-7.2,3.2-7.2,7.2c0,3.2,2,5.8,4.9,6.8c-2.8,1-4.9,3.6-4.9,6.8c0,3.1,2,5.8,4.8,6.8c-2.8,1-4.8,3.6-4.8,6.8c0,4,3.2,7.2,7.2,7.2
	h4.6c4,0,7.2-3.2,7.2-7.2c0-3.1-2-5.8-4.8-6.8C35.6,144.6,37.6,141.9,37.6,138.8z"/>
<path id="left-foot" fill="#424143" d="M47.5,178.4c-21.3,0-10.6,0-41.8,0c0-11.6,9.4-20.9,20.9-20.9
	C38.2,157.5,47.5,166.8,47.5,178.4z">
  <animate attributeName="fill" dur="5000ms" to="#f06d06" fill="freeze" />  
</path>
<path id="right-leg" fill="#424143" d="M90.3,138.9c0-3.2,2-5.8,4.9-6.8c-2.8-1-4.9-3.6-4.9-6.8c0-4,3.2-7.2,7.2-7.2h4.6
	c4,0,7.2,3.2,7.2,7.2c0,3.2-2,5.8-4.9,6.8c2.8,1,4.9,3.6,4.9,6.8c0,3.1-2,5.8-4.8,6.8c2.8,1,4.8,3.6,4.8,6.8c0,4-3.2,7.2-7.2,7.2
	h-4.6c-4,0-7.2-3.2-7.2-7.2c0-3.1,2-5.8,4.8-6.8C92.3,144.6,90.3,142,90.3,138.9z"/>
<path id="right-foot" fill="#424143" d="M80.4,178.4c21.3,0,10.6,0,41.8,0c0-11.6-9.4-20.9-20.9-20.9
	C89.7,157.5,80.4,166.9,80.4,178.4z"/>
<path id="left-eye-stem" fill="#424143" d="M49.8,15.4C49.8,6.9,42.9,0,34.4,0C25.9,0,19,6.9,19,15.4c0,7.4,5.2,13.5,12.1,15
	c0.3,2,1.8,10.6,6,17.8l5.9-3.4c-3.1-5.4-4.5-11.8-5-14.5C44.8,28.7,49.8,22.6,49.8,15.4z"/>
<circle id="left-eye" fill="#FFFFFF" cx="34.4" cy="15.4" r="10.6"/>
<circle id="left-pupil" fill="#424143" cx="34.4" cy="15.4" r="4.8"/>
<path id="right-eye-stem" fill="#424143" d="M78.1,15.4c0-8.5,6.9-15.4,15.4-15.4s15.4,6.9,15.4,15.4c0,7.4-5.2,13.5-12.1,15
	c-0.3,2-1.8,10.6-6,17.8l-5.9-3.4c3.1-5.4,4.5-11.8,5-14.5C83.1,28.8,78.1,22.7,78.1,15.4z"/>
<path id="body" fill="#424143" d="M64,80c-0.1,0-0.1,0-0.2,0C40.5,80,17.5,80,0,80c0,34.5,27.9,62.4,62.4,62.4c0.5,0,1,0,1.5,0
	c0.5,0,1,0,1.6,0c34.5,0,62.4-27.9,62.4-62.4C110.4,80,87.4,80,64,80z"/>
<path id="head" fill="#424143" d="M64,35.5L64,35.5C64,35.5,64,35.5,64,35.5C64,35.5,64,35.5,64,35.5c-0.1,0-0.1,0-0.1,0
	c0,0,0,0,0,0v0c-21,0.1-38,17.1-38,38.1c11,0,24.6,0,38,0c0.1,0,0.1,0,0.2,0c13.4,0,27,0,38,0C102,52.7,85,35.6,64,35.5z"/>
<circle id="right-eye" fill="#FFFFFF" cx="93.5" cy="15.4" r="10.6"/>
<circle id="right-pupil" fill="#424143" cx="93.5" cy="15.4" r="4.8"/>
<polygon id="mouth" fill="#FFFFFF" points="64,62 63.9,62 46.3,62 46.3,67.3 63.9,67.3 64,67.3 81.6,67.3 81.6,62 "/>
</svg>

<ol>
  <li>The right eye pulsates red with CSS @keyframes</li>
  <li>The left pupil expands lightgreen with SnapSVG</li>
  <li>The left foot turns to orange with &lt;animate></li>
</ol>
              
            
!

CSS

              
                svg {
  width: 150px;
  border: 10px solid #ccc;
  float: left;
  margin-right: 20px;
}

#right-eye {
  animation: redeye 2s infinite alternate;
}

@keyframes redeye {
  to {
    fill: red;
  }
}

body {
  padding: 20px;
}
h1 {
  margin: 0;
}
ol {
  list-style-position: inside;
}
li {
  margin: 0 0 5px 0;
}
              
            
!

JS

              
                var s = Snap("#robot");

var leftPupil = s.select("#left-pupil");

leftPupil.attr({
  fill: "green"
});

leftPupil.animate({
  r: 50,
  fill: "lightgreen"
}, 1000);
              
            
!
999px

Console