Multi Step Form
Multi Step Form
DOCTYPE html>
<html lang="en">
<head>
<meta
name="viewport"
/>
<title>Multi-Step Form</title>
<style>
*{
box-sizing: border-box;
body {
background: #f5f7fa;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
color: #222;
form {
background: #fff;
border-radius: 10px;
width: 320px;
max-width: 95vw;
position: relative;
input[type="radio"] {
display: none;
/* Step containers */
.form-step {
display: none;
display: block;
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(15px);
to {
opacity: 1;
transform: translateY(0);
/* Form titles */
h2 {
margin-bottom: 1rem;
color: #33475b;
font-weight: 700;
font-size: 1.5rem;
/* Form controls */
label {
display: block;
margin-bottom: 0.3rem;
font-weight: 600;
color: #44515e;
input,
select {
width: 100%;
margin-bottom: 0.8rem;
border-radius: 6px;
font-size: 1rem;
appearance: none;
input:focus,
select:focus {
outline: none;
border-color: #4f90fa;
label.required::after {
color: #d63447;
font-weight: 700;
/* Validation feedback */
input:invalid:not(:focus):not(:placeholder-shown) {
border-color: #d63447;
input:valid:not(:focus):not(:placeholder-shown) {
border-color: #2faa60;
.error-message {
color: #d63447;
font-size: 0.85rem;
margin-top: -0.6rem;
margin-bottom: 0.8rem;
display: none;
/* Show error message if input is invalid and not focused and required */
input:invalid:not(:focus):not(:placeholder-shown) + .error-message {
display: block;
.btn-group {
display: flex;
justify-content: space-between;
margin-top: 1rem;
.btn {
background: #4f90fa;
color: #fff;
font-weight: 700;
border-radius: 8px;
cursor: pointer;
user-select: none;
border: none;
text-align: center;
font-size: 1rem;
box-shadow: 0 4px 8px #3b6fd1aa;
.btn:hover:not([disabled]) {
background: #346ddb;
.btn:active:not([disabled]) {
background: #1e4cada;
.btn[disabled],
.btn[disabled]:hover {
background: #ccc;
cursor: not-allowed;
box-shadow: none;
.btn.prev {
background: #dee3ea;
color: #555;
box-shadow: none;
.btn.prev:hover {
background: #cfd6e3;
color: #444;
.btn.prev:active {
background: #b0b9cf;
}
/* Hide prev button on first step */
visibility: hidden;
display: none;
display: block;
button.submit-btn {
background: #2faa60;
border: none;
border-radius: 8px;
color: white;
font-weight: 700;
font-size: 1.1rem;
width: 100%;
cursor: pointer;
display: none;
margin-top: 1rem;
user-select: none;
}
button.submit-btn:hover {
background: #238045;
button.submit-btn:active {
background: #1f6d39;
form {
width: 90vw;
</style>
</head>
<body>
<h2>Personal Information</h2>
<input
type="text"
id="fname"
name="fname"
placeholder="John"
required
pattern=".{2,}"
autocomplete="given-name"
/>
<span class="error-message" >Please enter your first name (at least 2 characters).</span >
<input
type="text"
id="lname"
name="lname"
placeholder="Doe"
required
pattern=".{2,}"
autocomplete="family-name"
/>
<span class="error-message" >Please enter your last name (at least 2 characters).</span >
<input
type="email"
id="email"
name="email"
placeholder="[email protected]"
required
autocomplete="email"
/>
<span class="error-message">Please enter a valid email address.</span>
<div class="btn-group">
</div>
</section>
<h2>Address</h2>
<input
type="text"
id="street"
name="street"
required
autocomplete="street-address"
/>
<input
type="text"
id="city"
name="city"
placeholder="New York"
required
pattern=".{2,}"
title="City must be at least 2 characters"
autocomplete="address-level2"
/>
<span class="error-message" >Please enter your city (at least 2 characters).</span >
<input
type="text"
id="zip"
name="zip"
placeholder="10001"
required
pattern="\\d{5}"
autocomplete="postal-code"
/>
<div class="btn-group">
</div>
</section>
<h2>Payment Details</h2>
<input
type="text"
id="cardnumber"
name="cardnumber"
required
pattern="\\d{13,16}"
inputmode="numeric"
maxlength="19"
autocomplete="cc-number"
/>
<span class="error-message" >Please enter a valid card number (13-16 digits).</span >
<input
type="text"
id="expiry"
name="expiry"
placeholder="MM/YY"
required
pattern="(0[1-9]|1[0-2])\/?([0-9]{2})"
inputmode="numeric"
maxlength="5"
autocomplete="cc-exp"
/>
<input
type="password"
id="cvv"
name="cvv"
placeholder="123"
required
pattern="\\d{3,4}"
inputmode="numeric"
maxlength="4"
autocomplete="cc-csc"
/>
<div class="btn-group">
</div>
</section>
</form>
</body>
</html>