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

              
                <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

<h1> Pin Code form with autofocus + backspace navigation</h1>

<form id="codePinForm" class="text-left" onsubmit="handleSubmit(event)">
  <input type="checkbox" id="showCodePin" />
  <p>
    <input type="number" required autocomplete="off" oninput="handleInput(event)" onkeydown="handleKeydown(event)" onclick="handleClick(event)">
    <input type="number" required autocomplete="off" oninput="handleInput(event)" onkeydown="handleKeydown(event)" onclick="handleClick(event)">
    <input type="number" required autocomplete="off" oninput="handleInput(event)" onkeydown="handleKeydown(event)" onclick="handleClick(event)">
    <input type="number" required autocomplete="off" oninput="handleInput(event)" onkeydown="handleKeydown(event)" onclick="handleClick(event)">
    <input type="number" required autocomplete="off" oninput="handleInput(event)" onkeydown="handleKeydown(event)" onclick="handleClick(event)">
    <input type="number" required autocomplete="off" oninput="handleInput(event)" onkeydown="handleKeydown(event)" onclick="handleClick(event)">

    <label for="showCodePin" role="button" tabindex="0" title="show/hide">
      <span>👁️</span>
      <span>🙈</span>
    </label>
  </p>
  <input type="submit" />
  <input type="reset" onclick="handleReset(event)" />
</form>

<p id="result">🎉Your pin code is <strong></strong></p>



<div id="credits">
  <a href="https://twitter.com/bilelz/status/1389601484157882375" target="_blank" rel="noopener">bilelz</a> production©
</div>
              
            
!

CSS

              
                body {
  background: #ff5f6d;
  background: -webkit-linear-gradient(to right, #ffc371, #ff5f6d);
  background: linear-gradient(to right, #ffc371, #ff5f6d);
  color: #444;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  font-size: 16px;
  max-width: 320px;
  margin: 0 auto;
  padding: 0;
  box-sizing: border-box;
  text-align: center;
}

h1 {
  font-size: 20px;
  margin-bottom: 5em;
}

form {
  p {
    display: flex;
    align-items: center;
    justify-content: center;

    input {
      -webkit-appearance: none;
      appearance: none;
      -moz-appearance: textfield;
      box-sizing: border-box;
      height: 40px;
      width: 40px;
      background-color: transparent;
      border: 1px solid white;
      border-radius: 5px;
      margin: 0 5px;
      text-align: center;
      color: transparent;
      font-size: 24px;
      caret-color: transparent;
      transition: 0.15s ease-out;
      outline: none;
      box-shadow: inset 0 0 0 0 transparent;

      transition: 0.15s ease-in-out;
      perspective-origin: center;
      transform-style: preserve-3d;
      transform: perspective(500px) rotateX(0) rotateY(0);

      &:focus {
        box-shadow: inset 0 0 0 3px #1373f3;
      }

      &::selection {
        color: transparent;
      }

      &::-moz-selection {
        color: transparent;
      }

      &::-webkit-outer-spin-button,
      &::-webkit-inner-spin-button {
        -webkit-appearance: none;
        appearance: none;
        margin: 0;
      }

      &:valid {
        background-image: radial-gradient(white 7px, transparent 8px);
      }
    }
  }
}

#showCodePin {
  display: none;
  &:checked {
    & + p {
      label[for="showCodePin"] {
        span:first-child {
          display: none;
        }
        span:last-child {
          display: inline;
        }
      }

      input {
        transition: 0.15s;
        animation: reveal 0.3s ease-in-out;

        &:nth-child(1) {
          animation-delay: 0;
        }

        &:nth-child(2) {
          animation-delay: 0.05s;
        }
        &:nth-child(3) {
          animation-delay: 0.1s;
        }
        &:nth-child(4) {
          animation-delay: 0.15s;
        }
        &:nth-child(5) {
          animation-delay: 0.2s;
        }
        &:nth-child(6) {
          animation-delay: 0.25s;
        }

        color: white;
        background-image: none;

        &:focus::selection {
          color: white;
        }
      }
    }
  }
}

@keyframes reveal {
  0% {
    transform: perspective(500px) rotateX(0) rotateY(0) scale(-1, 1);
    color: transparent;
  }

  66% {
    transform: perspective(500px) rotateY(0deg) rotateY(90deg) scale(-1, 1);
    color: transparent;
    background-color: transparent;
  }

  100% {
    transform: perspective(500px) rotateY(0deg) rotateY(180deg) scale(-1, 1);
    color: white;
    background-color: transparent;
  }
}

label[for="showCodePin"] {
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  border: none;
  height: 40px;
  width: 40px;
  border-radius: 5px;
  padding: 0 8px;
  outline: none;
  transition: 0.15s ease-in-out;

  &:hover {
    background-color: rgb(255 255 255 / 50%);
  }

  &:focus {
    background-color: rgb(255 255 255 / 50%);
    box-shadow: 0 0 0 2px #fff;
  }

  &:active {
    box-shadow: inset 0 0 2px 2px #fff;
  }

  span:last-child {
    display: none;
  }
}

#result, input[type="reset"] {
  display: none;
}

form:valid {
  input[type="submit"] {
    display: none;
  }
  & + #result, input[type="reset"] {
    display: inline-block;
  }
}

input[type="reset"],
input[type="submit"] {
  -webkit-appearance: none;
  appearance: none;
  background-color: rgb(255 255 255 / 50%);
  border: 1px solid white;
  border-radius: 5px;
  margin: 0 5px;
  text-align: center;
  font-size: 1rem;
  font-family: inherit;
  padding: 5px 10px;
  outline: none;
  transition: 0.15s ease-in-out;

  &:hover {
    background: white;
  }

  &:focus {
    box-shadow: 0 0 0 2px #1373f3;
  }

  &:active {
    box-shadow: inset 0 0 2px 2px #1373f3;
  }
}

#credits {
  margin-top: 5em;
}

              
            
!

JS

              
                function handleClick(event: Event) {
  (event.currentTarget as HTMLInputElement).select();
}

function handleInput(event: Event) {
  const currentInput = event.currentTarget as HTMLInputElement;
  const nextInput = currentInput.nextElementSibling as HTMLInputElement;
  currentInput.value = `${currentInput.valueAsNumber}`; // parse number

  if (currentInput.value.length > 0) {
    currentInput.value = currentInput.value.slice(currentInput.value.length - 1); // keep the last number
    
    if (nextInput && nextInput.tagName === "INPUT") {
      nextInput.focus();
    } else {
      document.querySelector('input[type="reset"]').focus();
    }
  }
  showCodepin();
}

function handleKeydown(event: KeyboardEvent) {
  const currentInput = event.currentTarget as HTMLInputElement;
  const prevInput = (event.target as HTMLInputElement).previousElementSibling as HTMLInputElement;  
  
  if (event.key === "Backspace") {
    if (currentInput.value.length === 0 && prevInput && prevInput.tagName === "INPUT") {
      prevInput.focus();
    } else {
      currentInput.value = "";
    }
  } else {
    currentInput.focus();
  }
}

function handleSubmit(event: Event) {
  event.preventDefault();
}

function handleReset(event: Event) {
  document.querySelector('input[type="number"]').focus()
}

function showCodepin() {
  const codePin = [...document.querySelectorAll('input[type="number"]')].map((item) => item.value).join('');
  document.querySelector("#result strong").textContent = codePin;
}


// showtime 
setTimeout(() => {
 document.querySelector('input[type="submit"]').click();
},1000); 
              
            
!
999px

Console