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.

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

              
                <span id="type-text">...</span>
<span class="blinking-cursor">_</span>

              
            
!

CSS

              
                body
  min-height: 100vh
  padding: 0 10%
  background-color: #111
  color: #FFF
  font-size: 2em
  display: flex
  align-items: center

.blinking-cursor
  pointer-events: none
  user-select: none
  animation: blink 1s steps(2, start) infinite
  
  @keyframes blink
    to
      visibility: hidden

              
            
!

JS

              
                function init () {

  wait(1000).then(() => {
    clearText()
    typeText('Hello, ').then(typeLoop)
  })
  
  function typeLoop() {
    typeText('CodePen!')
      .then(() => wait(2000))
      .then(() => removeText('CodePen!'))
      .then(() => typeText('World!'))
      .then(() => wait(2000))
      .then(() => removeText('World!'))
      .then(typeLoop)
  }
  
}


// Source code 🚩

const elementNode = document.getElementById('type-text')
let text = ''

function updateNode () {
  elementNode.innerText = text
}

function pushCharacter (character) {
  text += character
  updateNode()
}

function popCharacter () {
  text = text.slice(0, text.length -1)
  updateNode()
}

function clearText () {
  text = ''
  updateNode()
}


function wait (time) {
  if (time === undefined) {
    const randomMsInterval = 100 * Math.random()
    time = randomMsInterval < 50 ? 10 : randomMsInterval
  }
  
  return new Promise(resolve => {
    setTimeout(() => {
      requestAnimationFrame(resolve)
    }, time)
  })
}

function typeCharacter (character) {
  return new Promise(resolve => {
    pushCharacter(character)
    wait().then(resolve)
  })
}

function removeCharacter () {
  return new Promise(resolve => {
    popCharacter()
    wait().then(resolve)
  })
}

function typeText (text) {
  return new Promise(resolve => {
    
    function type ([ character, ...text ]) {
      typeCharacter(character)
        .then(() => {
          if (text.length) type(text)
          else resolve()
        })
    }
    
    type(text)
  })
}

function removeText ({ length:amount }) {
  return new Promise(resolve => {
    
    function remove (count) {
      removeCharacter()
        .then(() => {
          if (count > 1) remove(count - 1)
          else resolve()
        })
    }
    
    remove(amount)
  })
}


init()

              
            
!
999px

Console