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

              
                <h1 class="form-heading">Application Form</h1>
<form class="application-form">
    <p class="helper-text">* denotes a required field</p>
    
    <div class="field-row">
        <label class="form-label" for="firstName">First name</label>
        <input type="text" id="firstName" class="field text-field first-name-field" required>
        <span class="message"></span>
    </div>
    
    <div class="field-row">
        <label class="form-label" for="initials">Initials</label>
        <input type="text" id="initials" class="field field-short text-field initials-field">
    </div>
    
    <div class="field-row">
        <label class="form-label cf" for="lastName">Last name</label>
        <input type="text" id="lastName" class="field text-field last-name-field" required>
        <span class="message"></span>
    </div>
    
    <div class="field-row">
        <label class="form-label" for="dateOfBirth">Date of birth</label>
        <input type="date" id="dateOfBirth" class="field date-field dob-field" min="1900-01-01" max="2015-09-18"  required>
        <span class="message"></span>
    </div>
    
    <div class="field-row">
        <label class="form-label" for="tel">Tel</label>
        <input type="tel" id="tel" class="field text-field tel-field" required>
        <span class="message"></span>
    </div>
    
    <div class="field-row">
        <label class="form-label" for="email">Email</label>
        <input type="email" id="email" class="field text-field email-field" required>
        <span class="message"></span>
    </div>
    
    <div class="field-row">
        <label class="form-label" for="website">Website</label>
        <input type="url" id="website" class="field text-field url-field website-field">
        <span class="message"></span>
    </div>
    
    <div class="field-row">
        <label class="form-label"></label>
        <button class="form-button">Apply now</button>
    </div>
</form>
              
            
!

CSS

              
                $color-invalid: red;
$color-valid: green;

@mixin field-outline($color) {
    outline: $color solid 2px;
}

@mixin message-invalid($message) {
    color: $color-invalid;
    content: $message;
}

* {
    outline: none;
}

.form-heading {
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size: 36px;
    font-weight: bold;
    margin: 5px;
}

.application-form {
    border: 1px solid black;
    box-sizing: border-box;
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    margin: 15px auto;
    padding: 15px;
    width: 600px;
}

.helper-text {
    font-size: 12px;
    margin-botom: 10px;
    text-align: right;
}

.field-row {
    position: relative;
    width: 100%;
}

.form-label {
    display: inline-block;
    font-size: 16px;
    margin: 0 5px 5px 0;
    text-align: right;
    width: 100px;
}

.field {
    border: 1px solid #ccc;
    box-sizing: border-box;
    display: inline-block;
    font-size: 16px;
    padding: 10px;
    margin-bottom: 15px;
    width: 240px;
    
    &.field-short {
        width: 70px;
    }
}

.message {
    display: inline-block;
}

.form-button {
    background: linear-gradient(180deg, #808080, #2a2a2a);
    border: none;
    border-radius: 2px;
    color: white;
    display: inline-block;
    padding: 10px;
    font-size: 16px;
    
}

:required + .message::before {
    content: "* ";
}

.text-field {
    &:focus:required:valid {
        @include field-outline($color-valid);
    }
    
    &:focus:required:invalid {
        @include field-outline($color-invalid);
    }
}

.date-field {
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    
    &:focus:in-range {
        @include field-outline($color-valid);
    }
    
    &:focus:out-of-range {
        @include field-outline($color-invalid);
    }
}

.website-field {
    &:focus:valid {
        @include field-outline($color-valid);
    }
    
    &:focus:invalid {
        @include field-outline($color-invalid);
    }
}

.first-name-field:focus:invalid + .message::after {
    color: $color-invalid;
    content: "Please enter your first name";
}

.last-name-field:focus:invalid + .message::after {
    @include message-invalid("Please enter your last name");
}

.dob-field:focus:out-of-range + .message::after {
    @include message-invalid("Date is out of range");
}

.tel-field:focus:invalid + .message::after {
    @include message-invalid("Invalid telephone number");
}

.email-field:focus:invalid + .message::after {
    @include message-invalid("Invalid email address");
}

.website-field:focus:invalid + .message::after {
    @include message-invalid("Invalid website URL");
}
              
            
!

JS

              
                
              
            
!
999px

Console