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

              
                <body>
    <div class="container">
        <div class="progress-bar">
            <div class="progress" id="progress"></div>
        </div>
        <h1>Tell us about yourself</h1>
        <form id="dynamicForm">
            <div class="form-group">
                <label for="name">What's your name?</label>
                <input type="text" id="name" required>
            </div>

            <div class="form-group">
                <label>Are you a student?</label>
                <div class="radio-group">
                    <div class="radio-option">
                        <input type="radio" name="isStudent" value="yes" id="studentYes">
                        <label for="studentYes">Yes</label>
                    </div>
                    <div class="radio-option">
                        <input type="radio" name="isStudent" value="no" id="studentNo">
                        <label for="studentNo">No</label>
                    </div>
                </div>
            </div>

            <div class="form-group hidden" id="studentFields">
                <label for="school">What school do you attend?</label>
                <input type="text" id="school">
                <label for="year">What year are you in?</label>
                <select id="year">
                    <option value="">Select year</option>
                    <option value="1">First Year</option>
                    <option value="2">Second Year</option>
                    <option value="3">Third Year</option>
                    <option value="4">Fourth Year</option>
                    <option value="5+">Fifth Year or Higher</option>
                </select>
            </div>

            <div class="form-group hidden" id="workFields">
                <label for="occupation">What's your occupation?</label>
                <input type="text" id="occupation">
                <label for="experience">Years of experience</label>
                <input type="number" id="experience" min="0">
            </div>

            <div class="form-group">
                <label for="email">Email address</label>
                <input type="email" id="email" required>
            </div>

            <button type="submit">Submit</button>
        </form>
    </div>
</body>
              
            
!

CSS

              
                :root {
            --primary: #f8c4c4;
            --secondary: #c4e3f8;
            --accent: #c4f8d4;
            --text: #4a4a4a;
            --background: #fafafa;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', system-ui, sans-serif;
        }

        body {
            background-color: var(--background);
            color: var(--text);
            line-height: 1.6;
            padding: 2rem;
        }

        .container {
            max-width: 600px;
            margin: 0 auto;
            background: white;
            padding: 2rem;
            border-radius: 12px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }

        h1 {
            color: var(--text);
            margin-bottom: 1.5rem;
            text-align: center;
        }

        .form-group {
            margin-bottom: 1.5rem;
            opacity: 1;
            transition: all 0.3s ease;
        }

        .form-group.hidden {
            display: none;
            opacity: 0;
        }

        label {
            display: block;
            margin-bottom: 0.5rem;
            font-weight: 500;
        }

        input[type="text"],
        input[type="email"],
        input[type="number"],
        select {
            width: 100%;
            padding: 0.75rem;
            border: 2px solid #e0e0e0;
            border-radius: 8px;
            font-size: 1rem;
            transition: border-color 0.3s ease;
        }

        input[type="text"]:focus,
        input[type="email"]:focus,
        input[type="number"]:focus,
        select:focus {
            outline: none;
            border-color: var(--secondary);
        }

        .radio-group {
            display: flex;
            gap: 1rem;
            margin-top: 0.5rem;
        }

        .radio-option {
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        button {
            background-color: var(--primary);
            color: var(--text);
            border: none;
            padding: 0.75rem 1.5rem;
            border-radius: 8px;
            font-size: 1rem;
            cursor: pointer;
            transition: transform 0.2s ease, background-color 0.2s ease;
            width: 100%;
        }

        button:hover {
            background-color: #f8b4b4;
            transform: translateY(-1px);
        }

        .progress-bar {
            height: 4px;
            background-color: #e0e0e0;
            border-radius: 2px;
            margin-bottom: 2rem;
            overflow: hidden;
        }

        .progress {
            height: 100%;
            background-color: var(--secondary);
            width: 0;
            transition: width 0.3s ease;
        }
              
            
!

JS

              
                const form = document.getElementById('dynamicForm');
        const studentFields = document.getElementById('studentFields');
        const workFields = document.getElementById('workFields');
        const progressBar = document.getElementById('progress');
        let currentProgress = 0;

        // Handle student/non-student radio buttons
        document.querySelectorAll('input[name="isStudent"]').forEach(radio => {
            radio.addEventListener('change', (e) => {
                if (e.target.value === 'yes') {
                    studentFields.classList.remove('hidden');
                    workFields.classList.add('hidden');
                    updateProgress(60);
                } else {
                    studentFields.classList.add('hidden');
                    workFields.classList.remove('hidden');
                    updateProgress(60);
                }
            });
        });

        // Update progress bar
        function updateProgress(value) {
            currentProgress = value;
            progressBar.style.width = `${value}%`;
        }

        // Handle form inputs for progress bar
        form.querySelectorAll('input, select').forEach(input => {
            input.addEventListener('input', () => {
                let filledFields = Array.from(form.querySelectorAll('input:not([type="radio"]), select'))
                    .filter(field => field.value.trim() !== '').length;
                let totalFields = Array.from(form.querySelectorAll('input:not([type="radio"]), select')).length;
                let progress = (filledFields / totalFields) * 100;
                updateProgress(progress);
            });
        });

        // Form submission
        form.addEventListener('submit', (e) => {
            e.preventDefault();
            
            // Collect form data
            const formData = {
                name: document.getElementById('name').value,
                isStudent: document.querySelector('input[name="isStudent"]:checked').value,
                email: document.getElementById('email').value
            };

            if (formData.isStudent === 'yes') {
                formData.school = document.getElementById('school').value;
                formData.year = document.getElementById('year').value;
            } else {
                formData.occupation = document.getElementById('occupation').value;
                formData.experience = document.getElementById('experience').value;
            }

            // You can handle the form data here (e.g., send to server)
            console.log('Form submitted:', formData);
            alert('Form submitted successfully!');
            form.reset();
            updateProgress(0);
        });
              
            
!
999px

Console