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="component">
  <p class="typewriter js-typewriter">
    Typewriters had been invented as early as 1714 by Henry Mill and reinvented in various forms throughout the 1800s. It was to be Sholes, however, who invented the first one to be commercially successful.
  </p>
  <button class="btn-replay" onclick="app.replay(event)">replay
  </button>
</div>
              
            
!

CSS

              
                $duration-typing: 300ms;
$duration-background: 1000ms;
$delay-unit: 100ms;
$color: #111;
html {
  font-size: 20px;
  @media(min-width: 600px) {
    font-size: 30px;
  }
}

body {
  margin: 0;
  font-family: Courier, Helvetica, sans-serif;
  background: #fafafa;
}

.component {
  padding: .5rem;
  text-align: center;
  margin: 0 auto;
  max-width: 1000px;
  .typewriter {
    margin: .5rem;
    padding: 1rem .5rem;
    text-align: left;
    font-weight: 300;
    > span {
      display: inline-block;
    }
    &.animate {
      > span > i {
        animation: typewriter $duration-typing forwards, background $duration-background forwards;
       //  animation: typewriter $duration-typing steps(1) forwards;
      }
    }
    > span > i {
      opacity: 0;
      // display: inline-block;
      color: $color;
      font-style: normal;
      font-size: 1em;
      min-width: .4em;
      border-radius: 2px;
      @for $i from 1 through 30 {
        &:nth-of-type(#{$i}) {
          animation-delay: $i*$delay-unit;
        }
      }
    }
  }
  .btn-replay {
    padding: .5rem;
    background: white;
    border: 0;
    box-shadow: 1px 1px 2px #777;
    text-transform: uppercase;
    cursor: pointer;
  }
}

@keyframes typewriter {
  50% {
    transform: scale(1.4);
  }
  100% {
    opacity: 1;
  }
}

@keyframes background {
  0% {
    //text-shadow: 0 0 2rem $color; // expensive anim
   background: rgba($color,.1);
    //box-shadow: 0 0 4rem rgba($color,.9); // expensive anim
  }
  100% {}
}
              
            
!

JS

              
                window.app = (_ => {

  let log = console.log.bind(console),
    messageElement = document.querySelector('.js-typewriter'),
    text = messageElement.innerText.trim();

  let words = text.split(' ');
  
  let work = [];

  words.forEach(word => {
    let splitWord = word.split('').map((char, index) => {
      return `<i>${char}</i>`;
    }).join('');
    work.push(splitWord);
  });  
  
  let formattedWords = work.map((word, index) => {
    return `<span>${word}</span>`;
  }).join(' ');

  messageElement.innerHTML = formattedWords;
  messageElement.classList.add('animate');

  return {
    replay: (event) => {
      messageElement.classList.remove('animate');
      messageElement.offsetHeight; // force reflow
      setTimeout(_ => {
        messageElement.classList.add('animate');
      });
    }
  };

})();
              
            
!
999px

Console