How to create: stacked form
- Previous Page News Subscription
- Next Page Responsive Form
Learn how to create stacked forms using CSS.
Stacked form
A vertically stacked form (where input fields and labels are placed vertically instead of horizontally):
How to create a stacked form
Step 1 - Add HTML:
Use the <form> element to handle input. You can find our PHP Tutorial for more information.
Add input controls (with matching labels) for each field:
<form action="/action_page.php"> <label for="fname">First Name</label> <input type="text" id="fname" name="firstname" placeholder="Your name.."> <label for="lname">Last Name</label> <input type="text" id="lname" name="lastname" placeholder="Your last name.."> <label for="country">Country</label> <select id="country" name="country"> <option value="australia">Australia</option> <option value="canada">Canada</option> <option value="usa">USA</option> </select> <input type="submit" value="Submit"> </form>
Step 2 - Add CSS:
/* Set the style for input fields */ input[type=text], select { width: 100%; padding: 12px 20px; margin: 8px 0; display: inline-block; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; } /* Set the style for the submit button */ input[type=submit] { width: 100%; background-color: #04AA6D; color: white; padding: 14px 20px; margin: 8px 0; border: none; border-radius: 4px; cursor: pointer; } /* Add background color for the submit button on hover */ input[type=submit]:hover { background-color: #45a049; }
Related Pages
Tutorial:HTML Form
Tutorial:CSS Form
- Previous Page News Subscription
- Next Page Responsive Form