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

              
                .content.typewriter
  p.text Hello stranger. How are you doing?    
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Vollkorn);

body
  font-family: 'Vollkorn' serif
  color: #333

.content
  text-align: center
  height: 50px
  line-height: 1.5
  font-size: 30px
  position: absolute
  top: 0
  bottom: 0
  margin: auto
  width: 100%

.typewriter
  .text
    display: inline
    visibility: hidden
    &:after
      content: ''
      display: inline-block
      height: 2px
      width: .9em
      background-color: #3498db
      transform: translateY(.2em)
      animation: blink .5s infinite linear
    &.is_type
      visibility: visible
    &.is_done
      visibility: visible
      &:after
        content: none

@keyframes blink
  0%   {opacity: 1}
  99%  {opacity: 0}
  100% {opacity: 1}
              
            
!

JS

              
                const typewriter = ($elm) => {
  const className_done = 'is_done';
  const className_run  = 'is_type';
  const typeSpeed = 100;
  
  return new Promise((resolve, reject) => {
    if($elm.length) {
      const $text = $elm.find('.text');
      const text  = $text.text();
      const chars = text.length;
      let index = 0;
      $text[0].innerHTML = '';
      $text[0].classList.remove(className_done);
      $text[0].classList.add(className_run);

      const write = () => {
        $text.append( text[index] );
        if(index < chars) {
          index += 1;
          setTimeout(() => write(), typeSpeed);
        } else {
          $text[0].innerHTML = text;
          $text[0].classList.replace(className_run, className_done);
          resolve('TYPEWRTER complete');
        }
      };
      write();
    } else {
      reject('TYPEWRTER no content');
    }
  });
};

// loop
const run = ($typewriter) => {
  typewriter($typewriter)
    .then(() => {
      setTimeout(() => run($typewriter), 3000);
    });
}

$(function() {
  const $typewriter = $('.typewriter');
  run($typewriter);
});
              
            
!
999px

Console