How do I center this form in css?
- Wrap your form in a div.
- Set the div's display to block and text-align to center (this will center the contained form).
- Set the form's display to inline-block (auto-sizes to content), left and right margins to auto (centers it horizontally), and text-align to left (or else its children will be center-aligned too).
HTML:
<div class="form">
<form name="Form1" action="mypage.asp" method="get">
...
</form>
</div>
CSS:
div.form
{
display: block;
text-align: center;
}
form
{
display: inline-block;
margin-left: auto;
margin-right: auto;
text-align: left;
}
Another way
body {
text-align: center;
}
form {
display: inline-block;
}
<body>
<form>
<input type="text" value="abc">
</form>
</body>