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

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

              
                <pre class="output"></pre>
<div class="container">
    <form action="" id="survey-form" class="form" autocomplete="on">
        <h1 id="title">Take this Survey</h1>
        <p id="description" class="underline">
            Thank you for taking the time to improve our service
        </p>
        <div class="form-control">
            <label class="floating" id="name-label" for="name">Name</label>
            <input
                type="text"
                name="name"
                id="name"
                autocomplete="name"
                placeholder="Jane Smith"
                required
            />

            <small></small>
        </div>
        <div class="form-control">
            <label class="floating" id="email-label" for="email">Email</label>
            <input
                type="email"
                autocomplete="email"
                name="email"
                id="email"
                placeholder="[email protected]"
                required
            />

          <small style="visibility: visible;">Error example</small>
        </div>
        <div class="form-control">
            <label class="floating" id="number-label" for="number"
                >Age (optional)</label
            >
            <input
                type="number"
                min="18"
                max="200"
                name="age"
                id="number"
                placeholder="32"
                autocomplete="age"
            />

            <small></small>
        </div>
        <div class="form-control">
            <label for="dropdown" class="underline-left">Choose one:</label>
            <select id="dropdown">
                <option>Rating</option>
                <option>1</option>
                <option>2</option>
                <option>3</option>
                <option>4</option>
                <option>5</option>
            </select>

        </div>
        <div class="form-control custom-inputs">
            <h6 class="underline-left">What food do you like? (select as many as you want)</h6>
            <label
                >Burgers
                <input
                    type="checkbox"
                    checked="checked"
                    value="burgers"
                />
                <span class="checkmark"></span>
            </label>
            <label
                >Vegetables
                <input type="checkbox" value="vegetables" checked="checked" />
                <span class="checkmark"></span>
            </label>

            <label
                >Chickun
                <input type="checkbox" value="chickun" />
                <span class="checkmark"></span>
            </label>

            <label
                >Tacos
                <input type="checkbox" value="tacos" />
                <span class="checkmark"></span>
            </label>

            <label
                >Toast
                <input type="checkbox" value="toast" />
                <span class="checkmark"></span>
            </label>
            <label
                >Pizza
                <input type="checkbox" value="pizza" />
                <span class="checkmark"></span>
            </label>
        </div>
        <div class="form-control custom-inputs">
            <p class="underline-left">Pick a number!</p>
            <label
                >One
                <input type="radio" value="1" name="radio" />
                <span class="checkmark"></span>
            </label>
            <label
                >Two
                <input type="radio" value="2" name="radio" />
                <span class="checkmark"></span>
            </label>
            <label
                >Three
                <input type="radio" value="3" name="radio" />
                <span class="checkmark"></span>
            </label>
            <label
                >Four
                <input type="radio" value="4" name="radio" />
                <span class="checkmark"></span>
            </label>
        </div>
                  <div class="form-control">
                <label class="underline-left" for="comments">Your Comments:</label>
                <textarea
                    name="comments"
                    id="comments"
                    rows="5"
                ></textarea>
            </div>
        <button id="submit" type="submit">Submit</button>
    </form>
</div>

<!-- <script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
 -->
              
            
!

CSS

              
                :root {
    --success-color: #2ecc71;
    --error-color: #e74c3c;
    --primary-color: #7b1594;
}

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

pre{
  font-family: Monaco, Courier;
}

@mixin fade-underline {
    content: "";
    position: absolute;
    bottom: 2px;
    left: 0;
    height: 2px;
    width: 100%;
    background: #444;
    background: linear-gradient(
        left,
        transparent 0%,
        #7b1594 50%,
        transparent 100%
    );
}

@mixin fade-underline-left {
    @include fade-underline;
    background: linear-gradient(left, #7b1594 30%, transparent 100%);
}

body {
    font-size: 16px;
    background-color: #f9fafb;
    font-family: "Open Sans", sans-serif;
    display: flex;
  flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    margin: 0;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1 {
    font-size: 1.8rem;
    margin-bottom: 1rem;
    text-align: center;
}

a {
    color: var(--primary-color);
}

p#description {
    text-align: center;
    font-style: italic;
    padding-bottom: 1rem;
    margin-bottom: 2rem;
}

.underline {
    position: relative;
    padding-bottom: 3px;
    bottom: 3px;
    &::after {
        @include fade-underline();
    }
    &-left {
        position: relative;
        padding-bottom: 3px;
        bottom: 3px;
        &::after {
            @include fade-underline-left();
        }
    }
}

.container {
    background: white;
    border-radius: 25px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3), 0 0 80px 80px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 600px;
    margin: 5%;
}

.form {
    padding: 1.5rem 1.8rem;
    button {
        cursor: pointer;
        background: var(--primary-color);
        border: 2px solid var(--primary-color);
        color: white;
        display: block;
        font-size: 16px;
        padding: 0.5rem;
        border-radius: 4px;
        width: 100%;
        margin-top: 1rem;
    }
}

.form-control {
    padding-bottom: 0.1rem;
    position: relative;
    & input,
    & select,
    & textarea {
        border: 2px solid #f0f0f0;
        border-radius: 4px;
        display: block;
        width: 100%;
        padding: 10px;
        margin: 1rem 0;
        font-size: 1rem;
    }

    label.floating {
        position: absolute;
        color: #333;
        display: block;
        margin-bottom: 5px;
        top: 8px;
        left: 14px;
    }
    input:valid,
    textarea:valid {
        background: white;
        z-index: -1;
    }
    input::placeholder {
        color: transparent;
    }
    input:focus,
    textarea:focus{
        border-color: var(--primary-color);
        outline: 0;
    }
    &.success,
    &.success input {
        border-color: var(--success-color);
    }
    &.error,
    &.error input {
        border-color: var(--error-color);
    }

    &.error small {
        visibility: visible;
    }

    small {
        position: absolute;
        bottom: -1px;
        font-size: 12px;
        opacity: 1;
        color: var(--error-color);
        visibility: hidden;
    }
    select {
        background-color: white;
        margin: 0;
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
        -webkit-appearance: none;
        -moz-appearance: none;
        background-image: linear-gradient(45deg, transparent 50%, gray 50%),
            linear-gradient(135deg, gray 50%, transparent 50%),
            linear-gradient(to right, #ccc, #ccc);
        background-position: calc(100% - 20px) calc(1em + 2px),
            calc(100% - 15px) calc(1em + 2px), calc(100% - 2.5em) 0.5em;
        background-size: 5px 5px, 5px 5px, 1px 1.5em;
        background-repeat: no-repeat;
    }
    select:focus {
        background-image: linear-gradient(45deg, #7b1594 50%, transparent 50%),
            linear-gradient(135deg, transparent 50%, #7b1594 50%),
            linear-gradient(to right, #ccc, #ccc);
        background-position: calc(100% - 15px) 1em, calc(100% - 20px) 1em,
            calc(100% - 2.5em) 0.5em;
        background-size: 5px 5px, 5px 5px, 1px 1.5em;
        background-repeat: no-repeat;
        border-color: var(--primary-color);
        outline: 0;
    }
    select:-moz-focusring {
        color: transparent;
        text-shadow: 0 0 0 #000;
    }
    &.custom-inputs {
        margin-top: 20px;
        label {
            display: inline-block;
            position: relative;
            padding: 10px 35px;
            margin-bottom: 12px;
            cursor: pointer;
            user-select: none;
            &:focus,
            &:visited,
            &:active {

            }
        }

        //Display as a list not inline
        label.list {
            display: block;
        }

        label input {
            position: absolute;
            opacity: 0;
            cursor: pointer;
            height: 0;
            width: 0;
        }

        .checkmark {
            position: absolute;
            top: 10px;
            left: 0;
            height: 25px;
            width: 25px;
            background-color: #eee;
        }

        .container:hover input ~ .checkmark {
            background-color: #ccc;
        }

        label input:checked ~ .checkmark {
            background-color: var(--primary-color);
        }

        .checkmark:after {
            content: "";
            position: absolute;
            display: none;
        }

        label input:checked ~ .checkmark:after {
            display: block;
        }

        label .checkmark:after {
            left: 9px;
            top: 5px;
            width: 5px;
            height: 10px;
            border: solid white;
            border-width: 0 3px 3px 0;
            transform: rotate(45deg);
        }
    }
}

.form-control .form-control.error .form-control input:focus + label.floating,
.form-control.active > label.floating {
    transform: scale(0.75) translate3d(-16px, -113%, 0);
    transition: all linear 0.1s;
    background: white;
}

.form-control .active input::placeholder {
    color: #6d6d6d;
}

              
            
!

JS

              
                const form = document.getElementById('survey-form');

var out = document.querySelector('.output');

function updateResult() {
  try {
    out.textContent = new URLSearchParams(Array.from(new FormData(form)));
  } catch (e) {
    out.textContent = e;
    out.className = 'error';
  }
}

form.addEventListener('submit', function handleSubmit(event){
  event.preventDefault();
  updateResult();
});

form.addEventListener('focusin', function handleFocus(event) {
    if (event.target.tagName == 'INPUT') {
        event.target.parentElement.classList.add('active');
    }
});

form.addEventListener('focusout', function handleBlur(event) {
    if (event.target.tagName === 'INPUT') {
        if (event.target.value === '')
            event.target.parentElement.classList.remove('active');
    }
});
              
            
!
999px

Console