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

              
                
<div class="animation-demo">

	<!-- 
		Here we have pasted in the contents of the <svg> (Scalable Vector Graphic) element from the Unicorn.svg file. This is considered an 'inline' SVG, because we are using the <svg> in our HTML inline (as it is).

		To make sure that browsers do not interpret the SVG as content, we need to set a 'role' attribute to the value of 'img' in the SVG element.

		For accessibility, to ensure that our <title> and <desc> elements are read by browsers that do not quite support them we use the 'aria-labelledby' and 'aria-describedby' attributes. These define the label and description of this SVG for accessibility devices.
	-->
	<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="-589 396 100 70" style="enable-background:new -589 396 100 70;" xml:space="preserve" role="img" aria-labelledby="unicorn-svg-title" aria-describedby="unicorn-svg-desc">


		<!--
			Adding a <title> element to our inline <svg> enables accessiblity tools to interpret a brief explanation of what our SVG is.

			The ID is important in this case to link the SVG to the title using 'aria-labelledby'
		-->
		<title id="unicorn-svg-title">A unicorn with a star on it</title>


		<!-- 
			Adding a <desc> element to our inline <svg> enables accessibility tools to interpret a more complete description for complex graphics.

			The ID is important in this case to link the SVG to the title using 'aria-describedby'
		-->
		<desc id="unicorn-svg-desc">A unicorn whose horn oscillates between two colours while a large star pops out and spins from its torso</desc>



		<!-- 
			Much like any other HTML element we can add classes to the pieces of our inline SVG to allow us to style the pieces individually.

			The <path> element defines a vector path in our SVG.
		-->
		<path class="unicorn-fill" d="M-491,397.2C-491.1,397.2-491,397.2-491,397.2c-3.6,2.4-12.5,8.4-13.7,9.2c-0.5-0.5-1-1-1.4-1.5c-0.1-0.4-0.2-0.9-0.2-1.3
c0-0.4,0.1-0.9-0.1-1.3c-0.8,0.6-1.5,1.5-2.6,1.7c-0.8,0.3-1.6,0.7-2.5,1c-0.1-0.2-0.2-0.5-0.5-0.6c-1.9-0.1-3.8,0.4-5.8,0.5
c-0.6,0-0.9,0.5-1.5,0.5c-0.5,0-1,0.4-1.5,0.5c-1.8,0.4-3.4,1.5-4.9,2.6c-0.7,0.6-1.5,0.8-2.2,1.3c-1.1,1.2-2.5,2-3.6,3.1
c-0.6,0.7-1.6,0.9-2.3,1.4c-0.7,0.4-1.4,0.8-2.1,1.2c-0.7,0.4-0.8,1.4-1.6,1.7c-1.4,0.7-3.1,0.9-4.7,0.9c-4.1-0.1-8.1-0.4-12.1-1.2
c-3.1-0.5-6.4-1-9.4,0.1c-2.2,0.8-4.1,2.1-6,3.5c-0.7,0.6-1.8,0.6-2.5,1.2c-1,0.7-2,1.4-2.7,2.4c-0.6,0.7-0.9,1.5-1.3,2.3
c-0.4,0.9-0.6,1.8-0.8,2.7c-0.2,1.3-0.7,2.6-0.9,3.9c-0.1,0.9-0.2,1.9-0.5,2.8c-0.2,0.7-0.4,1.3-0.6,2c-0.4,1.2-1,2.3-1.3,3.5
c-0.3,1-1,1.8-1.2,2.8c-0.2,0.9-0.9,1.7-1.3,2.5c-0.6,1.1-1,2.3-1.8,3.3c-1.2,1.7-2.5,3.6-2.8,5.8c-0.3,1.1-0.6,2.1-0.7,3.2
c-0.2,0.7,0.2,1.5,0.7,2c0.2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1c0.8-1.6,1.4-3.5,3-4.6
c1,0.9,2.1,1.4,3.3,1.9c1.3,0.9,2.6,1.7,4,2.4c0.7,0.3,0.7,1.1,1.2,1.6c0.2,0.3,0.5,0.5,0.8,0.6c0.7,0.4,1.5,0.1,2.2,0.1
c0.6-0.1,1.1-0.6,1.4-1.1c0.3-0.6,0.7-1,0.9-1.7c0.2-0.6-0.1-1.3-0.4-1.8c-0.7-2-2.3-3.5-3.2-5.4c-0.3-0.5-0.2-1.2-0.2-1.8
c0.1-1.2-0.1-2.5-0.7-3.6c1.8-1.5,9.3-7.8,12.6-10.6C-490.5,397.6-490.9,397.2-491,397.2z M-571.2,440c0.1-0.9,0.5-1.8,0.6-2.7
c0.2-1.3,0.5-2.6,0.9-3.9c0.4,1.3,0.7,2.6,0.6,4C-569.5,438.5-570.3,439.4-571.2,440z" />

		<!-- 
			The <polygon> element defines a shape in our SVG.
		-->
		<polygon class="unicorn-star" points="-541.5,421.4 -539.2,426.2 -533.9,427 -537.7,430.7 -536.8,435.9 -541.5,433.5 -546.2,435.9 
-545.3,430.7 -549.2,427 -543.9,426.2 " />

		<!--
			The <g> element defines a group of elements from our SVG.
		-->
		<g class="unicorn-horn-1">
			<polygon points="-501,403.8 -500.7,406.2 -498,404 -498.4,402.1  " />
			<polygon points="-496,400.4 -495.6,402 -492.9,399.6 -493.1,398.5  " />
		</g>
		<g class="unicorn-horn-2">
			<polygon points="-504.7,406.3 -503.2,408.3 -500.7,406.2 -501,403.8  " />
			<polygon points="-498.4,402.1 -498,404 -495.6,402 -496,400.4  " />
			<polygon points="-493.1,398.5 -492.9,399.6 -490.1,397.2 -490.5,396.8  " />
		</g>
	</svg>
</div>


              
            
!

CSS

              
                /*
	Using classes on our inline SVG, we can change the styling of different SVG elements. In this case, we can use SVG's "fill" property to change the colour of the fill on our unicorn.
*/
.unicorn-fill {
	fill: #AAA;
}


/*
	Our SVG was built using groups – they appear as <g> in our SVG code – which means that we can apply a class to that group and then select the child to style it. In this case we select the <polygon> which forms the horn to change the styling of it.
*/
.unicorn-horn-1 polygon {
	fill: pink;

	/*
		To call on an animation, we must refer to its 'name' as specified by @keyframes (further below).

		A good resource for all the animation properties we use in this tutorial is https://developer.mozilla.org/en-US/docs/Web/CSS/animation
	*/
	animation-name: horn-1-rainbow;

	/*
		Setting a duration over which the animation should run.
	*/
	animation-duration: 1s;

	/*
		We can set a number of iterations for which we want the animation to run (in this case, forever).
	*/
	animation-iteration-count: infinite;

	/*
		Because our animation runs 'from' and 'to' (see @keyframes further below), by default the switch between the beginning and end of the animation is not particularly smooth. In this case, we set the animation to alternate directions, which will allow it to smoothly transition back-and-forth.
	*/
	animation-direction: alternate;
}



/*
	Below we do much of the same as with did with .unicorn-horn-2, we just call on a slightly different animation for this portion of the horn.
*/
.unicorn-horn-2 polygon {
	fill: blue;
	animation-name: horn-2-rainbow;
	animation-duration: 1s;
	animation-iteration-count: infinite;
	animation-direction: alternate;
}

.unicorn-star {
	fill: yellow;

	/*
		The shorthand below specifies: duration easing iteration-count animation-name
	*/
	animation: 2s ease-in-out infinite star-pulse;
}



/*
	SVG's work with a couple of scales to determine their proportions (i.e. the viewBox attribute, how it is being rendered on the page), so to prevent our star from attempting to use the wrong scale when being 'transformed', we need to set an origin that specifies its center as the transformation point.
*/

polygon {
	-webkit-transform-origin: 50% 50%;
	-moz-transform-origin: 50% 50%;
	-o-transform-origin: 50% 50%;
	transform-origin: 50% 50%;
	transform-box: fill-box;
}


/*
	@keyframes
*/
@keyframes horn-1-rainbow {
	from {
		fill: pink;
	}
	to {
		fill: purple;
	}
}

@keyframes horn-2-rainbow {
	from {
		fill: blue;
	}
	to {
		fill: green;
	}
}

@keyframes star-pulse {
	0% {
		fill: yellow;
		transform: scale(1) rotate(0deg);
	}
	40% {
		fill: red;
		transform: scale(2) rotate(0deg);
	}
	60% {
		fill: red;
		transform: scale(2) rotate(360deg);
	}
	100% {
		fill: yellow;
		transform: scale(1) rotate(360deg);
	}
}
              
            
!

JS

              
                
              
            
!
999px

Console