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

              
                <div class="toaster"></div>

<main class="wrapper">
  <section class="section-form">
    <h1>GentleForm</h1>
    <p>
      Accessible and user-friendly HTML5 form validation library.<br>
      <a href="https://github.com/Zhouzi/GentleForm" target="_blank">GitHub Repo</a> - <a href="https://twitter.com/home?status=GentleForm%20-%20Accessible%20and%20user-friendly%20HTML5%20form%20validation%20library.%20http%3A%2F%2Fcodepen.io%2FZhouzi%2Ffull%2FQbBzZp%2F%20via%20%40zh0uzi" target="_blank">Tweet!</a>
    </p>

    <form name="signup" class="form" novalidate>
      <div class="form-group">
        <label for="name" class="form-label form-label--required">
          Name:
        </label>

        <div class="form-addon" data-states-for="name">
          <div class="form-addon__addon">
            <span class="icon-name"></span>
          </div>

          <input type="text"
                 id="name"
                 name="name"
                 class="form-input"
                 placeholder="Andrew"
                 required>
          
          <span class="form-addon__icon icon-valid"></span>
          <span class="form-addon__icon icon-invalid"></span>
        </div>

        <div data-errors-for="name">
          <small class="form-error"
                 data-errors-when="valueMissing">
            This field is required.
          </small>
        </div>
      </div>

      <div class="form-group">
        <label for="email" class="form-label form-label--required">
          Email:
        </label>

        <div class="form-addon" data-states-for="email">
          <div class="form-addon__addon">
            <span class="icon-email"></span>
          </div>

          <input type="email"
                 id="email"
                 name="email"
                 class="form-input"
                 placeholder="andrew@email.com"
                 required>

          <span class="form-addon__icon icon-valid"></span>
          <span class="form-addon__icon icon-invalid"></span>
        </div>

        <div data-errors-for="email">
          <small class="form-error"
                 data-errors-when="valueMissing">
            This field is required.
          </small>
          
          <small class="form-error"
                 data-errors-when="typeMismatch">
            Please enter a valid email address.
          </small>
        </div>
      </div>

      <div class="form-group">
        <label for="phone" class="form-label">
          Phone number:
        </label>

        <div class="form-addon" data-states-for="phone">
          <div class="form-addon__addon">
            <span class="icon-phone"></span>
          </div>

          <input type="text"
                 id="phone"
                 name="phone"
                 class="form-input"
                 placeholder="123 456 789"
                 pattern="[0-9]{3} [0-9]{3} [0-9]{3}">

          <span class="form-addon__icon icon-valid"></span>
          <span class="form-addon__icon icon-invalid"></span>
        </div>

        <div data-errors-for="phone">
          <small class="form-error"
                 data-errors-when="patternMismatch">
            Please enter a valid phone number.
          </small>
        </div>
      </div>

      <div class="form-group">
        <label for="password" class="form-label form-label--required">
          Password <span class="text-muted">(minimum 6 characters)</span>:
        </label>

        <div class="form-addon" data-states-for="password">
          <div class="form-addon__addon">
            <span class="icon-password"></span>
          </div>

          <input type="password"
                 id="password"
                 name="password"
                 class="form-input"
                 placeholder="********"
                 minlength="6"
                 required>

          <span class="form-addon__icon icon-valid"></span>
          <span class="form-addon__icon icon-invalid"></span>
        </div>

        <div data-errors-for="password">
          <small class="form-error"
                 data-errors-when="valueMissing">
            This field is required.
          </small>
          
          <small class="form-error"
                 data-errors-when="tooShort">
            Your password should be at least 6 characters long.
          </small>
        </div>
      </div>

      <div class="form-footer">
        <button type="submit" class="button">Sign up</button>
      </div>
    </form>
  </section>
</main>
              
            
!

CSS

              
                // To have a look at the styles related to GentleForm,
// jump straight to the bottom.



/*---------------------------------------------*\
    variables
\*---------------------------------------------*/

$font-family-heading: 'Francois One', sans-serif;
$font-family: 'Source Sans Pro', Helvetica, Arial, sans-serif;
$font-weight-light: 300;
$font-weight-bold: 700;
$font-size-base: 16px;

$gutter: 10px;
$border-radius: 2px;

$color-primary: #31d47d;
$background: #f4fcff;
$input-bg: #fff;
$text-color: darken($background, 86%);
$border-color: desaturate(darken($background, 16%), 56%);

$important-color: #f42866;



/*---------------------------------------------*\
    styles
\*---------------------------------------------*/

*,
*:before,
*:after {
  box-sizing: inherit;
}

html,
body {
  height: 100%;
}

.wrapper {
  min-height: 100%;
}

html {
  font-size: $font-size-base;
  box-sizing: border-box;
}

body {
  font-size: 1rem;
  line-height: 1.4;
  font-family: $font-family;
  font-weight: $font-weight-light;
  color: $text-color;
  background-color: $background;
}

small {
  font-size: .8rem;
}

h1 {
  display: inline-block;
  font-family: $font-family-heading;
  font-size: 3rem;
  line-height: 1.2;
  font-weight: $font-weight-bold;
  margin: 0 0 .8rem 0;
  border-bottom: 4px solid $color-primary;
}

p {
  margin: 0 0 2rem 0;
}

a {
  color: $color-primary;
  text-decoration: none;
  
  &:focus,
  &:hover {
    color: darken($color-primary, 10%);
  }
}

.text-muted {
  color: desaturate(lighten($text-color, 60%), 80%);
}

.wrapper {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.section-form {
  padding: 0 ($gutter * 2);
}

.form {
  display: block;
  max-width: 400px;
}

.form-group {
  margin-bottom: $gutter * 2;
}

.form-label,
.form-input {
  display: block;
  width: 100%;
}

.form-label {
  cursor: pointer;
  margin-bottom: $gutter / 2;
}

.form-label--required {
  position: relative;

  &:before {
    content: "*";
    position: absolute;
    left: -$gutter;
    color: $important-color;
  }
}

.form-input {
  padding: 10px;
  background-color: transparent;
  border: 0;

  &:focus {
    outline: none;
    background-color: desaturate(darken($background, 2%), 55%);
  }
}

.form-footer {
  text-align: right;
}

.form-error {
  color: $important-color;
  margin-top: $gutter / 2;
}

.button {
  color: white;
  white-space: nowrap;
  background-color: $color-primary;
  padding: 10px 20px;
  border: 0;
  border-radius: $border-radius;
  transition: all 150ms ease-out;

  &:focus,
  &:hover {
    background-color: darken($color-primary, 14%);
  }
}

.form-addon {
  position: relative;
  display: table;
  width: 100%;
  border: 1px solid $border-color;
  background-color: $input-bg;
  border-radius: $border-radius;

  .form-input,
  .form-addon__addon {
    display: table-cell;
    vertical-align: middle;
  }

  .form-input {
    width: 100%;
  }

  .form-addon__addon {
    position: relative;
    width: 40px;
    text-align: center;

    &:before {
      content: "";
      position: absolute;
      top: 4px;
      right: 0;
      height: calc(100% - 8px);
      border-right: 1px solid $border-color;
    }
  }
}

.form-addon__icon {
  position: absolute;
  color: $color-primary;
  font-size: .8rem;
  line-height: 1;
  top: 50%;
  transform: translateY(-50%);
  right: $gutter;
}

.toaster {
  position: fixed;
  z-index: 1;
  top: $gutter;
  right: $gutter;
}

.toast {
  color: #fff;
  padding: ($gutter * 2);
  margin-bottom: $gutter;
  border-radius: $border-radius;
  box-shadow: 0 2px 4px rgba(#000, .2);
  opacity: 0;
  transform: translateY(-$gutter) rotateY(40deg);
  transition: all 300ms ease;
  
  &.toast--show {
    transform: translateY(0) rotateY(0);
    opacity: 1;
  }
}

.toast--success {
  background-color: $color-primary;
}

.toast--error {
  background-color: $important-color;
}

footer {
  @extend .text-muted;
  margin-top: $gutter;
}



/*---------------------------------------------*\
    GentleForm related styles
\*---------------------------------------------*/

.form-addon {
  .form-addon__icon {
    transform: translateY(0);
    opacity: 0;
    transition: transform 150ms ease,
                opacity 150ms ease;
  }
  
  &.is-valid [class*="icon-valid"],
  &.is-invalid [class*="icon-invalid"] {
    transform: translateY(-50%);
    opacity: 1;
  }
  
  &.is-invalid {
    background-color: lighten($important-color, 42%);
    border-color: lighten($important-color, 20%);

    .form-addon__icon {
      color: $important-color;
    }

    .form-addon__addon:before {
      border-color: lighten($important-color, 20%);
    }
  }
}
              
            
!

JS

              
                // This is a demo of GentleForm:
// https://github.com/Zhouzi/GentleForm

const toaster = document.getElementsByClassName('toaster')[0]
const form = document.querySelector('form')

GentleForm(form, function (event) {
  event.preventDefault()
  
  if (this.isValid()) addToast('success', 'Yay, the form is valid!')
  else addToast('error', 'Oops, the form is invalid.')
})

function addToast (type, message) {
  const toast = document.createElement('div')

  toast.classList.add('toast')
  toast.classList.add('toast--' + type)
  toast.innerHTML = message

  toaster.appendChild(toast)

  toast.addEventListener('transitionend', function (event) {
    if (event.propertyName !== 'transform') return

    if (toast.classList.contains('toast--show')) {
      setTimeout(function () {
        toast.classList.remove('toast--show')
      }, 3000)
    } else {
      toaster.removeChild(toast)
    }
  }, false)

  setTimeout(() => toast.classList.add('toast--show'), 100)
}

              
            
!
999px

Console