Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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="wrap">
    <h1>CSS3 Animations</h1>
    <p><a href="https://moduscreate.com/blog/" target="_blank">
        Check out Modus Create blog post this was written for!
    </a></p>
    <p><a href="http://caniuse.com/#feat=css-animation" target="_blank">
        Here's a great resource for checking your CSS animation browser compatibility.
    </a></p>
    <h2>Transforms</h2>
    <div class="transforms">
        <ul>
            <li>
                <div id="noTransform">
                    <div>
                      <p>No Transform</p>
                    </div>
                </div>
            </li>
            <li>
                <div id="myTransform1">
                    <div>
                      <p>Transform Scale</p>
                  </div>
                </div>
            </li>
            <li>
                <div id="myTransform2">
                    <div>
                      <p>Transform Skew</p></div>
                </div>
            </li>
            <li>
                <div id="myTransform3">
                    <div>
                      <p>Transform Rotate</p></div>
                </div>
            </li>
            <li>
                <div id="myTransform4">
                    <div>
                      <p>Transform Translate</p></div>
                </div>
            </li>
        </ul>
    </div>
  
<h2>Transitions</h2>
    <div id="myAnim1">
        <div><p>Hover me!</p></div>
    </div>
    <p class="info"><span class="code">transition: left, 0, 1s, ease;</span></p>
    <div id="myAnim2">
        <div><p>Hover me!</p></div>
    </div>
    <p class="info"><span class="code">transition: transform, 0, 2s, ease;</span></p>
<h2>Keyframe Animations</h2>
    <div id="myAnim3">
        <div></div>
    </div>
    <p class="info">Keyframe animation with <span class="code">translateX(80px)</span>,
        <span class="code">rotateZ(180deg)</span> and <span class="code">animation-delay: 500ms</p>
    <div id="myAnim4">
        <div></div>
    </div>
    <p class="info">Keyframe animation with <span class="code">animation-delay: -500ms</span></p>
    <p>Example 4</p>
    <div id="myBounce">
        <div></div>
    </div>
    <p class="info">A negative Y value in the cubic-bezier curve can result in a bouncing effect.</span>
    <p>Example 5</p>
    <div id="myAnim5">
        <div class="one"><p>1</p></div>
        <div class="two"><p>2</p></div>
        <div class="three"><p>3</p></div>
        <div class="four"><p>4</p></div>
    </div>
    <p class="info">This is a 3D animation that rotates the cube by 90 degrees every 2 seconds with
        <span class="code">animation-timing-function: ease-in-out</span></p>
    <p>Example 6</p>
    <div id="myAnim6">
        <div class="one"><p>1</p></div>
        <div class="two"><p>2</p></div>
        <div class="three"><p>3</p></div>
        <div class="four"><p>4</p></div>
    </div>
    <p class="info">This is a 3D animation that rotates the cube 360 degrees with
        <span class="code">animation-timing-function: linear</span></p>
    <p>To hide the backs of your elements/images, you can set
        <span class="code">backface-visibility: hidden;</span></p>
</div>
              
            
!

CSS

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

html {
  body {
    background: #494E5A;
    color: #f7f1ee;
    font: 300 14px 'Nunito', sans-serif;

    .wrap {
      margin : 1em auto;
      padding: 3em 2em;
      width: 60%;

      a {
        color: coral;
        text-decoration: none;
        &:hover {
          border-bottom: 1px dotted coral;
        }
        &:active, &:focus, &:visited {
          color: coral;
          text-decoration: none;
        }
      }
      
      h1, h2, h3, p, span, a {
        font-weight: 300;
      }
      
      h1 {
        margin: 0;
      }
      
      h2 {
        margin: 1.5em 0 0 0;
      }

      p {
        margin: 1.5em 0 1em;
        &.info {
          display: inline-block;
          left: 176px;
          margin: 0;
          padding: 0;
          position: relative;
          top: -70px;
          white-space: normal;
          width: 560px;
          line-height: 1.75;
        }
      }

      .code {
        background: #dfdfdf;
        border-radius: 3px;
        color: #666666;
        display: inline;
        font-family: monospace;
        padding: 0.1em .25em;
      }

      .transforms {
        height: 120px;
        ul {
          display: inline;
          margin:  0;
          padding: 0;
          li {
            display: inline;
            list-style: none;
            margin:  0;
            padding: 0;
            div {
              display: inline-block;
              float: left;
              margin: 0 3em 0 0;
            }
          }
        }
      }
      
      #myAnim1, #myAnim2, #myAnim3, #myBounce, #myAnim4, 
      #myAnim5, #myAnim6, #myAnim7, #myTransform1, #myTransform2, 
      #myTransform3, #myTransform4, #noTransform
      {
        min-height: 80px;
        min-width: 80px;
        div {
          background:       #1FAB31;
          background-image: url("https://moduscreate.com/wp-content/themes/moduscreate-web/images/default-blog-image.jpg");
          background-size:  contain;
          border: 1px dashed #999;
          height: 80px;
          line-height: 80px;
          margin: 1em 0;
          opacity: 0.8;
          position: relative;
          text-align: center;
          width: 80px;
          p {
            line-height: 1em;
            margin: 0.5em 0;
            text-shadow: 1px 1px 1px #000000;
          }
        }
      }
      
      #noTransform {
      }
      
      #myTransform1 {
        -webkit-transform: scale(1.25);
        -moz-transform:    scale(1.25);
        transform:         scale(1.25);
      }
      
      #myTransform2 {
        -webkit-transform: skew(10deg);
        -moz-transform:    skew(10deg);
        transform:         skew(10deg);
       /* 
        * Note that properties such as margin remain
        * with the element and its transformation
        */
        margin-right: 1em;
        margin-left: 2em;
      }
      
      #myTransform3 {
        -webkit-transform: rotate(180deg);
        -moz-transform:    rotate(180deg);
        transform:         rotate(180deg);
       /* 
        * Note that properties such as margin remain
        * with the element and its transformation
        */
        margin: 1.2em 0 0 3em;
        div {
          margin: 0;
        }
      }
      
      #myTransform4 {
        -webkit-transform: translateX(7em);
        -moz-transform:    translateX(7em);
        transform:         translateX(7em); 
      }
      
      #myAnim1, #myAnim2, #myAnim3, #myBounce, #myAnim4, 
      #myAnim5, #myAnim6, #myAnim7, #myTransform1, #myTransform2, 
      #myTransform3, #myTransform4, #noTransform
      {
        min-height: 80px;
        min-width: 80px;
        div {
          background:       #1FAB31;
          background-image: url("https://moduscreate.com/wp-content/themes/moduscreate-web/images/default-blog-image.jpg");
          background-size:  contain;
          border: 1px dashed #999;
          height: 80px;
          line-height: 80px;
          margin: 1em 0;
          opacity: 0.8;
          position: relative;
          text-align: center;
          width: 80px;
          p {
            line-height: 1em;
            margin: 0.5em 0;
            text-shadow: 1px 1px 1px #000000;
          }
        }
      }
      
      #myAnim1 {
        div {
          &:hover {
            transform: translate(50px);
            -webkit-transition-delay: 0;
            -webkit-transition-duration: 1s;
            -webkit-transition-property: transform;
            -webkit-transition-timing-function: ease;
            /*
             * The transition properties can be condensed to one line:
             * transition: property duration timing-function delay;
             */
            -moz-transition-delay: 0;
            -moz-transition-duration: 1s;
            -moz-transition-property: transform;
            -moz-transition-timing-function: ease;
            transition-delay: 0;
            transition-duration: 1s;
            transition-property: transform;
            transition-timing-function: ease;
          }
        }
      }

      #myAnim2 {
        div {
          &:hover {
            -webkit-transform: rotate(180deg);
            -webkit-transition-delay: 0;
            -webkit-transition-duration: 2s;
            -webkit-transition-property: transform;
            -webkit-transition-timing-function: ease;
            -moz-transform: rotate(180deg);
            -moz-transition-delay: 0;
            -moz-transition-duration: 2s;
            -moz-transition-property: transform;
            -moz-transition-timing-function: ease;
            transform: rotate(180deg);
            transition-delay: 0;
            transition-duration: 2s;
            transition-property: transform;
            transition-timing-function: ease;
          }
        }
      }
        
        #myAnim3 {
        -webkit-animation-name:            mySquare;
        -webkit-animation-delay:           500ms;
        -webkit-animation-duration:        4s;
        -webkit-animation-iteration-count: infinite;
        -webkit-animation-timing-function: ease-in-out;
        -webkit-transform-origin:          40px 40px;
        /*
         *  "ease-in-out" is a keyword used to describe a cubic-bezier function.
         *  You can also define your own cubic-bezier curves
         */
        -webkit-animation-timing-function: cubic-bezier(.5, 0, .5, 1);

        -moz-animation-name:            mySquare;
        -moz-animation-delay:           500ms;
        -moz-animation-duration:        4s;
        -moz-animation-iteration-count: infinite;
        -moz-animation-timing-function: ease-in-out;
        -moz-animation-timing-function: cubic-bezier(.5, 0, .5, 1);
        -moz-transform-origin:          40px 40px;
        animation-name:            mySquare;
        animation-delay:           500ms;
        animation-duration:        4s;
        animation-iteration-count: infinite;
        animation-timing-function: ease-in-out;
        animation-timing-function: cubic-bezier(.5, 0, .5, 1);
        transform-origin:          40px 40px;
      }

      #myAnim4 {
        -webkit-animation-name:            mySquare;
        /*
         *  Using a negative value in animation-delay will
         *  result in the animation behaving as though
         *  that time had already passed.
         */
        -webkit-animation-delay:           -500ms;
        -webkit-animation-duration:        4s;
        -webkit-animation-iteration-count: infinite;
        -webkit-animation-timing-function: cubic-bezier(.5, 0, .5, 1);
        -webkit-transform-origin:          40px 40px;
        -moz-animation-name:            mySquare;
        -moz-animation-delay:           -500ms;
        -moz-animation-duration:        4s;
        -moz-animation-iteration-count: infinite;
        -moz-animation-timing-function: cubic-bezier(.5, 0, .5, 1);
        -moz-transform-origin:          40px 40px;
        animation-name:            mySquare;
        animation-delay:           -500ms;
        animation-duration:        4s;
        animation-iteration-count: infinite;
        animation-timing-function: cubic-bezier(.5, 0, .5, 1);
        transform-origin:          40px 40px;
      }

      // Animation with keyframes for the "rolling" square
      @-webkit-keyframes mySquare {
        0%       { -webkit-transform: translateX(0px) rotateZ(0deg); }
        50%      { -webkit-transform: translateX(80px) rotateZ(180deg); }
        100%     { -webkit-transform: translateX(0px) rotateZ(0deg); }
        // You can shortcut "0%" and "100%" as "from" and "to"
        from, to { -webkit-transform: translateX(0px) rotateZ(0deg); }
      }
      @-moz-keyframes mySquare {
        from, to { -moz-transform: translateX(0px) rotateZ(0deg); }
        50%      { -moz-transform: translateX(80px) rotateZ(180deg); }
      }
      @keyframes mySquare {
        from, to { transform: translateX(0px) rotateZ(0deg); }
        50%      { transform: translateX(80px) rotateZ(180deg); }
      }

      #myBounce {
        position: relative;

        div {
          margin-bottom: 2em;
          -webkit-animation-name:            bounce;
          -webkit-animation-direction:       alternate;
          -webkit-animation-duration:        0.5s;
          -webkit-animation-iteration-count: infinite;
          -webkit-animation-timing-function: cubic-bezier(0, -0.37, 0.2, 0.9);
          /*  Note that time, X (0 and 0.9), can not have a negative
           *  value in the animation-timing-function.
           *  The Y values (-0.37 and 0.2), however, can.
           */
          -moz-animation-name:            bounce;
          -moz-animation-direction:       alternate;
          -moz-animation-duration:        0.5s;
          -moz-animation-iteration-count: infinite;
          -moz-animation-timing-function: cubic-bezier(0, -0.37, 0.2, 0.9);
          animation-name:            bounce;
          animation-direction:       alternate;
          animation-duration:        0.5s;
          animation-iteration-count: infinite;
          animation-timing-function: cubic-bezier(0, -0.37, 0.2, 0.9);
        }
      }
      // Animation for bouncing box
      @-webkit-keyframes bounce {
        0%   { -webkit-transform: scaleY(0.95) scaleX(1.05) translateY(0); }
        100% { -webkit-transform: scaleY(1.05) scaleX(0.95) translateY(-80px); }
      }
      @-moz-keyframes bounce {
        0%   { -moz-transform: scaleY(0.95) scaleX(1.05) translateY(0); }
        100% { -moz-transform: scaleY(1.05) scaleX(0.95) translateY(-80px); }
      }
      @keyframes bounce {
        0%   { transform: scaleY(0.95) scaleX(1.05) translateY(0); }
        100% { transform: scaleY(1.05) scaleX(0.95) translateY(-80px); }
      }

      #myAnim5 {
        -webkit-animation-name:            myCube;
        -webkit-animation-duration:        8s;
        -webkit-animation-iteration-count: infinite;
        -webkit-transform-origin:          40px 40px 0;
        -webkit-transform-style:           preserve-3d;
        -webkit-animation-timing-function: ease-in-out;
        -moz-animation-name:            myCube;
        -moz-animation-duration:        8s;
        -moz-animation-iteration-count: infinite;
        -moz-transform-origin:          40px 40px 0;
        -moz-transform-style:           preserve-3d;
        -moz-animation-timing-function: ease-in-out;
        animation-name:            myCube;
        animation-duration:        8s;
        animation-iteration-count: infinite;
        transform-origin:          40px 40px 0;
        transform-style:           preserve-3d;
        animation-timing-function: ease-in-out;
        div {
          margin: 0;
          position: absolute;
        }
        // Use transforms to make sure all sides face the correct way
        .one   {
          -webkit-transform: translateZ(40px);
          -moz-transform: translateZ(40px);
          transform: translateZ(40px);
        }
        .two   {
          -webkit-transform: rotateY(90deg) translateZ(40px);
          -moz-transform: rotateY(90deg) translateZ(40px);
          transform: rotateY(90deg) translateZ(40px);
        }
        .three {
          -webkit-transform: rotateY(180deg) rotateX(0deg) translateZ(40px);
          -moz-transform: rotateY(180deg) rotateX(0deg) translateZ(40px);
          transform: rotateY(180deg) rotateX(0deg) translateZ(40px);
        }
        .four  {
          -webkit-transform: rotateY(270deg) translateZ(40px);
          -moz-transform: rotateY(270deg) translateZ(40px);
          transform: rotateY(270deg) translateZ(40px);
        }
      }
      // Animation for first spinning cube
      @-webkit-keyframes myCube {
        0%    { -webkit-transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg); }
        25%   { -webkit-transform: rotateY(-90deg); }
        50%   { -webkit-transform: rotateY(-180deg); }
        75%   { -webkit-transform: rotateY(-270deg); }
        100%  { -webkit-transform: rotateY(-360deg); }
      }
      @-moz-keyframes myCube {
        0%    { -moz-transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg); }
        25%   { -moz-transform: rotateY(-90deg); }
        50%   { -moz-transform: rotateY(-180deg); }
        75%   { -moz-transform: rotateY(-270deg); }
        100%  { -moz-transform: rotateY(-360deg); }
      }
      @keyframes myCube {
        0%    { transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg); }
        25%   { transform: rotateY(-90deg); }
        50%   { transform: rotateY(-180deg); }
        75%   { transform: rotateY(-270deg); }
        100%  { transform: rotateY(-360deg); }
      }

      #myAnim6 {
        -webkit-animation-name: myCube2;
        -webkit-animation-duration: 4s;
        -webkit-animation-iteration-count: infinite;
        -webkit-transform-origin: 40px 40px 0;
        -webkit-transform-style: preserve-3d;
        -webkit-animation-timing-function: linear;
        -moz-animation-name: myCube2;
        -moz-animation-duration: 4s;
        -moz-animation-iteration-count: infinite;
        -moz-transform-origin: 40px 40px 0;
        -moz-transform-style: preserve-3d;
        -moz-animation-timing-function: linear;
        animation-name: myCube2;
        animation-duration: 4s;
        animation-iteration-count: infinite;
        transform-origin: 40px 40px 0;
        transform-style: preserve-3d;
        animation-timing-function: linear;
        div {
          margin: 0;
          position: absolute;
          -webkit-backface-visibility: hidden;
          -moz-backface-visibility: hidden;
          backface-visibility: hidden;
        }
        // Use transforms to make sure all sides face the correct way
        .one   {
          -webkit-transform: translateZ(40px);
          -moz-transform: translateZ(40px);
          transform: translateZ(40px);
        }
        .two   {
          -webkit-transform: rotateY(90deg) translateZ(40px);
          -moz-transform: rotateY(90deg) translateZ(40px);
          transform: rotateY(90deg) translateZ(40px);
        }
        .three {
          -webkit-transform: rotateY(180deg) rotateX(0deg) translateZ(40px);
          -moz-transform: rotateY(180deg) rotateX(0deg) translateZ(40px);
          transform: rotateY(180deg) rotateX(0deg) translateZ(40px);
        }
        .four  {
          -webkit-transform: rotateY(270deg) translateZ(40px);
          -moz-transform: rotateY(270deg) translateZ(40px);
          transform: rotateY(270deg) translateZ(40px);
        }
      }
      // Animation for second rotating cube
      @-webkit-keyframes myCube2 {
        from  { -webkit-transform: rotateY(0deg); }
        to    { -webkit-transform: rotateY(-360deg); }
      }
      @-moz-keyframes myCube2 {
        from  { -moz-transform: rotateY(0deg); }
        to    { -moz-transform: rotateY(-360deg); }
      }
      @keyframes myCube2 {
        from  { transform: rotateY(0deg); }
        to    { transform: rotateY(-360deg); }
      }
    }
  }
}

              
            
!

JS

              
                
              
            
!
999px

Console