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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

            
              <section class="header">
  <h1>CSS Sprite Sheet Animations - Explained</h1>
  <div class="credits">
    <p>Sprite sheet by <a href="https://www.mozilla.org/en-US/firefox/partners/">Mozilla</a></p>
    <p>Demonstration by <a href="https://codepen.io/birjolaxew">Birjolaxew</a></p>
  </div>
</section>

<div class="content">
  <div class="viewport anim steps speed no-border no-shadow"></div>
  <p>Animated sprite sheets are quite simple. Here's how they're done:</p>
  
  <p>You start off with a "viewport". This is simply the element that you want the image to be seen in.</p>
  <div class="viewport no-bg"></div>
  
  <p>Next thing you do is set a <code>background-image</code> for the viewport (translucent image is not visible) to the <a href="https://www.mozilla.org/media/img/firefox/partners/foxtail.png">sprite sheet you want to use</a>.</p>
  <div class="no-shadow-left viewport"></div>
  
  <p>Now to the nifty stuff!</p>
  <p>Let <code>[anim-width]</code> be image width minus the width of your starting frame.</p>
  <p>Set the <code>background-position</code> of the viewport to animate from <code>0 0</code> to <code>-[anim-width] 0</code>.</p>
  <p>This animates from the left side of the first frame, to the left side of the last frame.</p>
  <div class="anim viewport"></div>
    
  <p>Change the <code>animation-timing-function</code> to <code>steps([number-of-frames])</code>.</p>
  <p>This moves the background image one frame at a time.</p>
  <div class="viewport anim steps"></div>
  
  <p>Ramp down <code>animation-duration</code> to speed up the animation.</p>
  <div class="viewport anim steps speed"></div>
  
  <p>And you're done!</p>
  <div class="example container"></div>
  
  <p>This was done with a horizontal sprite sheet - if you're using a vertical sprite sheet, simply animate the <code>y</code> position of the background instead of the <code>x</code> position.</p>
</div>
            
          
!

CSS

            
              @import url(https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700);

/* Actual content stuff! */
.viewport {
  margin:0 auto 50px;
  height:156px;
  width:156px;
  background:#262729 url(https://www.mozilla.org/media/img/firefox/partners/foxtail.png);
  position:relative;
  border: 4px solid #da4e48;
}
.viewport::before, .viewport::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 7020px;
  background: inherit;
  z-index: -1;
  opacity: .2;
}
.viewport::after { left: initial; right: 0; }

.no-bg { background-image: none; }
.no-shadow::before, .no-shadow::after, .no-shadow-left::after { content: initial; }
.no-border { border: none; }
.anim { animation: animate 44s linear infinite; }
.steps { animation-timing-function: steps(44); }
.speed { animation-duration: 3.75s; }

@keyframes animate {  
    0% {background-position: 0 0; }
    100% {background-position: -6864px 0;}
}

/* STYLE */
html, body {
  margin:0;
  padding:0;
  height:100%;
  background:#262729;
  overflow-x:hidden;
}
.header {
  height:50px;
  margin-bottom:40px;
  font-family:"Ubuntu", sans-serif;
  font-weight:500;
  color:#b4b4b4;
}
.header h1 {
  width:480px;
  height:100%;
  z-index:13;
  
  margin:0 auto;
  padding:20px 0 0;
  
  font-weight:500;
  text-align:center;
  
  box-shadow:inset 0 -4px #da4e48;
}
.header .credits {
  width:220px;
  
  margin:0;
  position:fixed;
  top:15px;
  right:35px;
  
  font-weight:700;
  color:#676767;

  z-index:15;
}
.credits p {
  margin:0;
}
a {
  color:#88d;
}
.content {
  font-family:"Ubuntu", sans-serif;
  font-weight:400;
  color:#ddd;
  z-index:5;
  position:relative;
}
.content p {
  text-align:center;
}
code {
  font-style:italic;
}
            
          
!

JS

            
              
            
          
!
999px

Console