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

              
                 <!-- tabs -->
    <div class="input-settings">
      <ul class="tabs">
        <li class="tab allow active">
          <span class="title">Allow</span>
        </li>
        <li class="tab prevent">
          <span class="title">Prevent</span>
        </li>
        <div class="slider"></div>
      </ul>
    </div>
    <!-- END tabs -->

    <!-- input -->
    <div class="wrapper">
      <input class="primary" type="text" pattern="[0-9]" />
      <span class="label">try digits</span>
    </div>
    <!--END input -->

    <!-- made in jssecrets.com -->
    <a class="jssecrets" href="https://jssecrets.com/" target="_blank"
      >jssecrets.com</a
    >
    <!-- made in jssecrets.com -->
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;800&display=swap");
@import url("https://fonts.googleapis.com/css2?family=Urbanist:wght@500&display=swap");
@import url("https://fonts.googleapis.com/css2?family=Nanum+Pen+Script&display=swap");
*,
::before,
::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Poppins", sans-serif;
}

ul {
  list-style: none;
}

body {
  height: 100vh;
  background: hsl(225, 14%, 12%);
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  color: #292d34;
}

input.primary {
  width: 320px;
  border: 2px solid rgb(80, 121, 247);
  box-shadow: 0 4px 20px rgba(80, 121, 247, 0.4);
  color: rgb(80, 121, 247);
  background: transparent;
  outline: none;
  font-size: 24px;
  padding: 16px;
  border-radius: 12px;
  transition: all 0.8s ease-out;
  opacity: 1;
}
@media (max-width: 400px) {
  input.primary {
    width: 220px;
    padding: 8px;
  }
}

.input-settings {
  width: 320px;
  border-radius: 10px;
  background-color: hsl(225, 14%, 17%);
  border: 1.5px solid rgba(0, 0, 0, 0.38);
  box-shadow: 0 8px 32px 0 hsl(225, 14%, 12%);
  backdrop-filter: blur(40px);
  padding: 16px;
  position: absolute;
  left: 50%;
  top: 5%;
  transform: translate(-50%, -5%);
  opacity: 1;
  transition: all 0.7s ease-out;
}
@media (max-width: 400px) {
  .input-settings {
    width: 220px;
    padding: 8px;
  }
}

.tabs {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}
.tabs .slider {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 100%;
  width: 50%;
  background: linear-gradient(45deg, rgb(245, 205, 81) 0%, rgb(247, 206, 81) 100%);
  box-shadow: 0 4px 20px rgba(245, 205, 81, 0.4);
  border-radius: 9px;
  z-index: 0;
  transition: all 0.3s linear;
}
.tabs .tab {
  width: 50%;
  height: 100%;
  display: block;
  text-align: center;
  cursor: pointer;
  padding: 16px 0 16px 0;
  border-radius: 9px;
  font-size: 16px;
  z-index: 1;
  position: relative;
  color: #7c828d;
  transition: all 0.3s linear;
}
.tabs .tab:hover {
  color: #f7ce51;
}
.tabs .tab .title {
  font-size: 16px;
}
@media (max-width: 400px) {
  .tabs .tab .title {
    font-size: 14px;
  }
}
.tabs .tab.active .title {
  font-weight: 900;
  color: hsl(225, 14%, 12%);
}
.tabs .tab:nth-of-type(1).active ~ .slider {
  left: 0%;
}
.tabs .tab:nth-of-type(2).active ~ .slider {
  left: 50%;
}

.wrapper {
  position: relative;
}
.wrapper .label {
  position: absolute;
  top: 100px;
  left: 50%;
  transform: translateX(-50%);
  color: white;
  font-family: "Nanum Pen Script", cursive;
  font-size: 32px;
}

.jssecrets {
  font-weight: 500;
  text-decoration: none !important;
  font-family: "Urbanist";
  padding: 16px;
  background: #ffc805;
  color: #000000;
  font-size: 1.2em;
  letter-spacing: 0.2px;
  border-radius: 8px;
  box-shadow: 0px 4px 12px rgba(184, 144, 0, 0.1882352941), 0px 8px 24px rgba(184, 144, 0, 0.3764705882);
  position: absolute;
  bottom: 24px;
  right: 24px;
  transition: all 0.3s;
}

.jssecrets:hover {
  transform: translateY(-4px);
}
              
            
!

JS

              
                // Variables
const tabs = document.querySelectorAll('.tabs .tab');
const input = document.querySelector('.primary');

// Regular Expressions

// digits only
const regex = /\d/;
let allow = true;

// Functions
// 1. Set active tab
const setActiveTab = (event) => {
  // sliding tabs functionality
  document.querySelector('.tab.active').classList.remove('active');
  event.currentTarget.classList.add('active');
  //
  if (event.currentTarget.classList.contains('allow')) {
    allow = true;
  } else {
    allow = false;
  }

  // clear input
  input.value = '';
};

// 2. Input filter
const inputFilter = (event) => {
  // catch pressed key's code
  // and convert it to an actual character
  let symbol = String.fromCharCode(event.keyCode);

  if (allow) {
    if (!regex.test(symbol)) {
      event.preventDefault();
    }
  } else {
    if (regex.test(symbol)) {
      event.preventDefault();
    }
  }
};

// Event Listeners
// sliding tabs event
tabs.forEach((tab) => {
  tab.addEventListener('click', setActiveTab);
});
// input event
// input.addEventListener('keypress', inputFilter);
input.addEventListener('keypress', inputFilter);

              
            
!
999px

Console