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

              
                <form class='row' action="POST" action="https://httpbin.org/forms/post" novalidate>
    <section class='column'>
        <fieldset>
            <div class="field">
                <input id='goodbye' type='text' pattern='Goodbye' title='Valid when "Goodbye"' autocomplete="off" required/>
                <label for='goodbye'>You say "Goodbye"</label>
                <span class='error'>Only valid when "Goodbye"</span>
            </div>
        </fieldset>        
        
        <fieldset>
            <div class="field">
                <input id='hello' type='text' pattern='Hello' title='Valid when blank or "Hello"' autocomplete="off" placeholder="Hello?"/>
                <label for='hello'>And I say "Hello"... maybe?</label>
                <span class='error'>Valid when blank or "Hello"</span>
            </div>
        </fieldset>
        
        <button type='submit'>Submit</button>
        <button type='button'>Reset</button>
    </section>
</form>
              
            
!

CSS

              
                @use postcss-cssnext;
@use postcss-apply;
@use postcss-custom-media;
@use postcss-nested;
@use postcss-mixins;
@use lost;
@lost flexbox flex;

:root {
    --color-dark-gray: #373B44;
    --color-red: #BD5532;
    --color-green: #73C8A9;
    --color-wheat: #E1B866;
    --color-muted-wheat: color(var(--color-wheat) blackness(60%));
    --color-tan: #DEE1B6;
    --label-font-size: 1.5rem;
    
    --neutral {
        border-color: var(--color-wheat);
        color: var(--color-wheat);
        
        & ~ label {
            color: var(--color-muted-wheat);
        }

        &:required ~ label:before {
            color: var(--color-tan);
        }
    }
    --invalid {
        border-color: var(--color-red);
        color: var(--color-red);
        box-shadow: 0 5px 5px color(var(--color-red) blackness(75%));
        
        & ~ label,
        &:required ~ label:before {
            color: var(--color-red);
        }
        
        & ~ .error {
            display: block;
        }
    }
    --valid {
        border-color: var(--color-green);
        color: var(--color-green);
        
        & ~ label,
        &:required ~ label:before {
            color: var(--color-green);
        }
    }
}

* {
    box-sizing: border-box;
}

body {
    background-color: var(--color-dark-gray);
    font-family: 'Droid Sans', sans-serif;
}

.row {
    lost-center: 50%;
    lost-align: middle-center;
}

.column {
    lost-column: 1;
}

form {
    height: 100vh;

    fieldset {
        border: none;
    }
    
    .field {
        position: relative;
        padding-top: calc( var(--label-font-size) + 1rem); /* Allow label to show above */
        margin-bottom: 1rem;
    }

    label {
        font-family: 'Oswald', sans-serif;
        display: block;
        position: absolute;
        top: 0;
        font-size: var(--label-font-size);
        color: var(--color-muted-wheat);
        text-transform: uppercase;
        white-space: nowrap;
    }
    
    input {
        @apply --neutral;
        border: 5px solid;
        box-shadow: 0 5px 5px rgba(0, 0, 0, 0.5);
        padding: 1rem;
        border-radius: 5px;
        width: 100%;
        font-size: 2rem;
        outline: none;
        
        &:required ~ label:before {
            content: '*';
            margin-right: 5px;
        }
        
        &::placeholder {
            color: color(var(--color-muted-wheat) alpha(20%));
        }
    }

    .error {
        display: none;
        color: var(--color-red);
        margin: 1rem 0 1rem 1.2rem;
    }

    button {
        background-color: var(--color-dark-gray);
        border: 3px solid var(--color-muted-wheat);
        color: var(--color-muted-wheat);
        padding: 0.75rem;
        border-radius: 5px;
        box-shadow: 0 3px 3px rgba(0, 0, 0, 0.5);
        margin: 1rem;
        font-weight: bold;
        text-transform: uppercase;
        cursor: pointer;
        outline: none;
        transition: all 0.15s ease-out;

        &:hover, &:focus {
            border-color: var(--color-tan);
            color: var(--color-tan);
            
        }
    }
}

/* 
    If it's valid, mark it as so.
*/
form input:valid {
    @apply --valid;
}

/* 
    This is for optional input elements that are empty (because placeholder is showing).
    The input will at least need a placeholder with a single space in order for this to work.
    
    Example: <input placeholder=" " />
*/
form input:optional:valid:placeholder-shown,
form input:optional:valid:placeholder-shown:focus {
    @apply --neutral;
}

/*
    Whenever the form is submitted and invalid, we'll put a "submitted" class on the form.
    This will then show the valid/invalid state of the inputs.
    It will also allow all inputs to show their valid/invalid on changes.
*/
/* Uncomment below to allow state update on focus */
/* form input:focus, */
form.submitted input {
    &:invalid {
        @apply --invalid;
    }

    /* Needed to specify optional as there not enough specificity when the input is empty */
    &:valid,
    &:optional:valid,
    &:optional:valid:placeholder-shown:focus {
        @apply --valid;
    }
}
              
            
!

JS

              
                // ---
// --- Form
// ---

const form = document.forms[0];

function markFormSubmitted() {
    form.classList.add("submitted");
}

function onSubmit(e) {
    
    // This will force HTML validation even if we mark the form as 'novalidate'
    if ( !this.reportValidity() ) {
        e.preventDefault();
        markFormSubmitted();
    } else {
        alert('Form is valid!');
    }

    e.preventDefault(); // Should be removed when you actually want to submit
}

form.addEventListener("submit", onSubmit);

// ---
// --- Reset Button
// ---

const reset = document.querySelector("button[type=button]");

reset.addEventListener("click", () => {
    form.reset();
    form.classList.remove("submitted");
});

              
            
!
999px

Console