How to create: inline forms
- Previous Page Pop-up Form
- Next Page Clear Input Box
Learn how to create responsive inline forms using CSS.
Responsive inline forms
Adjust the browser window size to see the effect (labels and inputs will stack, not side by side on smaller screens):
How to create inline forms
Step 1 - Add HTML:
Use the <form> element to handle input. You can learn more about this in our PHP tutorial.
<form class="form-inline" action="/action_page.php"> <label for="email">Email:</label> <input type="email" id="email" placeholder="Enter email" name="email"> <label for="pwd">Password:</label> <input type="password" id="pwd" placeholder="Enter password" name="pswd"> <label> <input type="checkbox" name="remember"> Remember me </label> <button type="submit">Submit</button> </form>
Second step - Add CSS:
/* Set the style for the form - display items horizontally */ .form-inline { display: flex; flex-flow: row wrap; align-items: center; } /* Add some margin to each label */ .form-inline label { margin: 5px 10px 5px 0; } /* Set the style for input fields */ .form-inline input { vertical-align: middle; margin: 5px 10px 5px 0; padding: 10px; background-color: #fff; border: 1px solid #ddd; } /* Set the style for the submit button */ .form-inline button { padding: 10px 20px; background-color: dodgerblue; border: 1px solid #ddd; color: white; } .form-inline button:hover { background-color: royalblue; } /* Add responsiveness - display form controls vertically instead of horizontally on screens with a width less than 800 pixels */ @media (max-width: 800px) { .form-inline input { margin: 10px 0; } .form-inline { flex-direction: column; align-items: stretch; } }
Related Pages
Tutorial:HTML Form
Tutorial:CSS Form
- Previous Page Pop-up Form
- Next Page Clear Input Box