Toggle navigation
☰
Home
HTML
CSS
Scripting
Database
<!DOCTYPE html> <title>My Example</title> <!-- ====================================================================== CSS - Place this in your <head> or in an external stylesheet. ====================================================================== --> <style> :root { --msh-padding: 4rem 1.5rem; --msh-bg-color: #f1f5f9; --msh-card-bg: #ffffff; --msh-text-color: #475569; --msh-headline-color: #0f172a; --msh-input-border: #94a3b8; --msh-input-focus-border: #0ea5e9; --msh-cta-bg: #0ea5e9; --msh-cta-hover-bg: #0284c7; --msh-cta-text-color: #ffffff; --msh-back-btn-color: #475569; --msh-max-width: 650px; } .multi-step-hero { box-sizing: border-box; font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; background-color: var(--msh-bg-color); padding: var(--msh-padding); width: 100%; display: flex; justify-content: center; align-items: center; } .multi-step-hero * { box-sizing: border-box; } .msh-card { max-width: var(--msh-max-width); width: 100%; background-color: var(--msh-card-bg); padding: 2.5rem; border-radius: 12px; box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1); text-align: center; } .msh-card .step-indicator { font-size: 0.9rem; font-weight: 600; color: var(--msh-text-color); margin-bottom: 1rem; } .msh-card .title { color: var(--msh-headline-color); font-size: clamp(1.8rem, 5vw, 2.5rem); font-weight: 700; line-height: 1.2; margin: 0 0 1.5rem; } .msh-card .form-step { display: none; /* Hide all steps by default */ } .msh-card .form-step.active { display: block; /* Show only the active step */ } .msh-card .form-input { width: 100%; background-color: #fff; border: 1px solid var(--msh-input-border); padding: 0.9rem 1rem; font-size: 1rem; border-radius: 8px; color: #0f172a; margin-bottom: 1rem; } .msh-card .form-input:focus { outline: none; border-color: var(--msh-input-focus-border); box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.3); } .msh-card .button-group { margin-top: 1.5rem; display: flex; justify-content: space-between; align-items: center; } .msh-card .btn { background-color: var(--msh-cta-bg); color: var(--msh-cta-text-color); border: none; padding: 0.9rem 1.5rem; font-size: 1rem; font-weight: 600; border-radius: 8px; cursor: pointer; transition: background-color 0.3s ease; text-decoration: none; } .msh-card .btn:hover { background-color: var(--msh-cta-hover-bg); } .msh-card .btn-back { background-color: transparent; color: var(--msh-back-btn-color); } .msh-card .btn-back:hover { background-color: #e2e8f0; } .sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border-width: 0; } </style> <!-- ====================================================================== HTML - Place this in your <body> where you want the component to appear. ====================================================================== --> <section class="multi-step-hero"> <form class="msh-card" id="multiStepForm" action="#" method="POST"> <p class="step-indicator" id="stepIndicator">Step 1 of 3</p> <!-- Step 1 --> <div class="form-step active" data-step="1"> <h1 class="title">Create Your Free Account</h1> <label for="msh-email" class="sr-only">Email Address</label> <input type="email" id="msh-email" name="email" class="form-input" placeholder="you@example.com" required> <div class="button-group"> <span><!-- empty span for spacing --></span> <button type="button" class="btn" data-next>Continue →</button> </div> </div> <!-- Step 2 --> <div class="form-step" data-step="2"> <h2 class="title">Tell Us Your Name</h2> <label for="msh-name" class="sr-only">Full Name</label> <input type="text" id="msh-name" name="name" class="form-input" placeholder="e.g., Alana Turing" required> <div class="button-group"> <button type="button" class="btn btn-back" data-back>← Back</button> <button type="button" class="btn" data-next>Next Step →</button> </div> </div> <!-- Step 3 --> <div class="form-step" data-step="3"> <h2 class="title">Set Your Password</h2> <label for="msh-password" class="sr-only">Password</label> <input type="password" id="msh-password" name="password" class="form-input" placeholder="Choose a secure password" required minlength="8"> <div class="button-group"> <button type="button" class="btn btn-back" data-back>← Back</button> <button type="submit" class="btn">Create Account</button> </div> </div> </form> </section> <!-- ====================================================================== JavaScript - Place this right before your closing </body> tag. ====================================================================== --> <script> (function() { const multiStepForm = document.getElementById('multiStepForm'); if (!multiStepForm) return; const stepIndicator = document.getElementById('stepIndicator'); const steps = Array.from(multiStepForm.querySelectorAll('.form-step')); const totalSteps = steps.length; let currentStep = 1; function showStep(stepNumber) { steps.forEach((step, index) => { step.classList.toggle('active', index + 1 === stepNumber); }); if(stepIndicator) { stepIndicator.textContent = `Step ${stepNumber} of ${totalSteps}`; } currentStep = stepNumber; } multiStepForm.addEventListener('click', (e) => { if (e.target.matches('[data-next]')) { showStep(currentStep + 1); } else if (e.target.matches('[data-back]')) { showStep(currentStep - 1); } }); // Initialize the form to show the first step showStep(currentStep); })(); </script>