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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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="input"></div>
<div class="keyboard">
  <div class="keyrow">
    <div class="key visible">1</div>
    <div class="key visible">2</div>
    <div class="key visible">3</div>
    <div class="key visible">4</div>
    <div class="key visible">5</div>
    <div class="key visible">6</div>
    <div class="key visible">7</div>
    <div class="key visible">8</div>
    <div class="key visible">9</div>
    <div class="key visible">0</div>
    <div class="key close visible">X</div>
    <div class="key invisible">^</div>
    <div class="key invisible">´</div>
    <div class="key invisible">`</div>
    <div class="key invisible">'</div>
    <div class="key invisible">~</div>
    <div class="key invisible">€</div>
    <div class="key invisible">ß</div>
    <div class="key invisible">Ä</div>
    <div class="key invisible">Ö</div>
    <div class="key invisible">Ü</div>
    <div class="key close invisible">X</div>
  </div>
  <div class="keyrow">
    <div class="key visible">Q</div>
    <div class="key visible">W</div>
    <div class="key visible">E</div>
    <div class="key visible">R</div>
    <div class="key visible">T</div>
    <div class="key visible">Z</div>
    <div class="key visible">U</div>
    <div class="key visible">I</div>
    <div class="key visible">O</div>
    <div class="key visible">P</div>
    <div class="key fn visible">⬅</div>
    <div class="key invisible">*</div>
    <div class="key invisible">\</div>
    <div class="key invisible">|</div>
    <div class="key invisible">/</div>
    <div class="key invisible">[</div>
    <div class="key invisible">]</div>
    <div class="key invisible">{</div>
    <div class="key invisible">}</div>
    <div class="key invisible">(</div>
    <div class="key invisible">)</div>
    <div class="key fn invisible">⬅</div>
  </div>
  <div class="keyrow">
    <div class="key visible">A</div>
    <div class="key visible">S</div>
    <div class="key visible">D</div>
    <div class="key visible">F</div>
    <div class="key visible">G</div>
    <div class="key visible">H</div>
    <div class="key visible">J</div>
    <div class="key visible">K</div>
    <div class="key visible">L</div>
    <div class="key fn visible">?.,</div>
    <div class="key fn visible">↩</div>
    <div class="key invisible">+</div>
    <div class="key invisible">#</div>
    <div class="key invisible">&</div>
    <div class="key invisible">%</div>
    <div class="key invisible">$</div>
    <div class="key invisible">=</div>
    <div class="key invisible">"</div>
    <div class="key invisible">!</div>
    <div class="key invisible">?</div>
    <div class="key fn invisible">AB</div>
    <div class="key fn invisible">↩</div>
  </div>
  <div class="keyrow">
    <div class="key fn visible">⇧</div>
    <div class="key visible">Y</div>
    <div class="key visible">X</div>
    <div class="key visible">C</div>
    <div class="key visible">V</div>
    <div class="key visible">B</div>
    <div class="key visible">N</div>
    <div class="key visible">M</div>
    <div class="key visible"> ⏘</div>
    <div class="key visible">.</div>
    <div class="key visible">,</div>
    <div class="key fn invisible">⇧</div>
    <div class="key invisible"><</div>
    <div class="key invisible">></div>
    <div class="key invisible">@</div>
    <div class="key invisible">;</div>
    <div class="key invisible">:</div>
    <div class="key invisible">-</div>
    <div class="key invisible">_</div>
    <div class="key invisible"> ⏘</div>
    <div class="key invisible"></div>
    <div class="key invisible"></div>
  </div>
 </div>
<br /><br />
<div class="key visible btn left">←</div>
<div class="key visible btn right">→</div>
<div class="key visible btn up">↑</div>
<div class="key visible btn down">↓</div>
<div class="key visible btn enter">↵</div>
              
            
!

CSS

              
                body {
  background: black;
}
.input {
  margin: 50px 0;
  min-height: 30px;
  color: white;
  font-family: sans-serif;
  text-align: center;
  font-size: 24px;
}
.keyboard.lowercase {
  text-transform: lowercase;
}
.keyrow {
  margin-top: -8px;
  display: table;
  border-collapse: separate;
  border-spacing: 8px;
}
.key {
  box-sizing: border-box;
  width: 48px;
  height: 48px;
  border: 2px solid white;
  border-radius: 4px;
  text-align: center;
  vertical-align: middle;
  font-family: sans-serif;
  font-size: 24px;
  color: white;
  will-change: transform;
  transition: transform 0.2s ease;
}
.key.invisible {
  display: none;
}
.key.visible {
  display: table-cell;
}
.key > small {
  font-size: 50%;
}
.key.fn {
  background: #333;
  text-transform: uppercase;
}
.key.close {
  border-radius: 50%;
  border-color: grey;
  color: grey;
  text-transform: uppercase;
}
.key.focus {
  outline: none;
  border-color: black;
  background: white;
  color: red;
}
.key.pressed {
  transform: scale(1.2)
}

.key.btn {
  display: table-cell;
}
.btn:hover {
  cursor: pointer;
  outline: none;
  border-color: black;
  background: white;
  color: red;
}
.btn:active {
  transform: scale(0.95)
}
              
            
!

JS

              
                (function() {
  var currentInput = ""
  var focused = {row: 0, key: 0}
  var uppercase = true
  var specialChars = false

  function getElementByPosition(row, key) {
    var rows = $('.keyrow:nth-child('+(focused.row+1)+')')
    var keys = rows.children('.key.visible')
    return $(keys[key])
  }

  function getFocusedElement() {
    return getElementByPosition(focused.row, focused.key)
  }

  function setFocus(row, key) {
    getFocusedElement().removeClass('focus')
    focused = {row: row, key: key}
    getFocusedElement().addClass('focus')
  }
  setFocus(0,0)

  function toggleCapitals() {
    if (uppercase)
      $('.keyboard').addClass('lowercase')
    else
      $('.keyboard').removeClass('lowercase')
    uppercase = !uppercase
  }

  $('.btn').on('click', function (e) {
    var target = $(e.target)
    if (target.hasClass('left'))
      goLeft()
    else if (target.hasClass('right'))
      goRight()
    else if (target.hasClass('up'))
      goUp()
    else if (target.hasClass('down'))
      goDown()
    else if (target.hasClass('enter'))
      click()
  });

  function goLeft() {
    if (focused.key === 0)
      setFocus(focused.row, 10)
    else
      setFocus(focused.row, focused.key-1)
  }

  function goRight() {
    if (focused.key === 10)
      setFocus(focused.row, 0)
    else
      setFocus(focused.row, focused.key+1)
  }

  function goUp() {
    if (focused.row === 0)
      setFocus(3, focused.key)
    else
      setFocus(focused.row-1, focused.key)
  }

  function goDown() {
    if (focused.row === 3)
      setFocus(0, focused.key)
    else
      setFocus(focused.row+1, focused.key)
  }

  function click() {
    var el = getFocusedElement()
    el.addClass('pressed')
    setTimeout(function () {el.removeClass('pressed')}, 200)
    var clicked = el.text()
    console.log(clicked)
    if (el.hasClass('close'))
      alert('closed keyboard')
    else if (clicked == '⬅') {
      if(currentInput.length >= 1)
        currentInput = currentInput.slice(0, -1);
    } else if (clicked == '↩')
      alert('sent pw is "' + currentInput + '"')
    else if (clicked == '⇧')
      toggleCapitals()
    else if (clicked == '?.,' || clicked == 'AB')
      toggleSpecialChars()
    else {
      if (!uppercase)
        currentInput += clicked.toLowerCase().substring(0,1)
      else
        currentInput += clicked.substring(0,1)
    }
    $('.input').text(currentInput)
  }

  function toggleSpecialChars() {
    //TODO implement special chars
    var visibles = $('.keyrow > .key.visible')
    var invisibles = $('.keyrow > .key.invisible')
    visibles.removeClass('visible').addClass('invisible')
    invisibles.removeClass('invisible').addClass('visible')
    setFocus(focused.row, focused.key)
  }
})()
              
            
!
999px

Console