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

              
                <div class="wrapper">
  <section>
    <h2>Form Validation with HTML/CSS</h2>
    <form class="css-form">
      <input type="email" id="email" required placeholder="Email">
      <input type="password" id="password" minlength="8" required placeholder="Password">
      <button type="submit">Submit</button>
    </form>
  </section>

  <section>
    <h2>Form Validation with JavaScript</h2>
    <form id="js-form">
      <input id="email-js" placeholder="Email">
      <input id="password-js" placeholder="Password">
      <button id="submit-js">Submit</button>
    </form>
  </section>
</div>
              
            
!

CSS

              
                .wrapper {
  display: flex;
  gap: 10px;
}

section {
  width: 50%;
  border: 1px solid grey;
  padding: 50px;
}

@media screen and (max-width: 960px) {
  .wrapper {
    flex-direction: column;
  }
  section {
    width: calc(100% - 100px);
  }
}

form {
  display: flex;
  flex-direction: column;
}

input {
  margin-bottom: 15px;
  padding: 10px;
}

.css-form input:valid {
  border: green 1px solid;
}

button {
  padding: 10px;
  background-color: #003366;
  color: white;
  border: none;
  cursor: pointer;
  width: 100%;
}

              
            
!

JS

              
                document.getElementById("submit-js").addEventListener("click", () => {
  const email = document.getElementById("email-js").value;
  const password = document.getElementById("password-js").value;
  let valid = true;

  if (!email.includes("@")) {
    alert("Please enter a valid email");
    valid = false;
  }

  if (password.length < 8) {
    alert("Password must be at least 8 characters long");
    valid = false;
  }

  if (valid) {
    alert("Form submitted successfully!");
  }
});

              
            
!
999px

Console