Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to align form at the center of the page in html/css

Tags:

html

css

I am new to html/css. i am trying to build up my own form and i am trying to align it in the center. I used the align property in css but its not working.

Html code:

<!DOCTYPE HTML>
<head>
    <title>Web Page Having A Form</title>
    <link rel = "stylesheet" type="text/css" href="Form.css">
</head>
<body>
    <h1>Create a New Account</h1>
      <form >
       <table>
        <tr>
         <td>Name :</td> <td><input type="text" name="name"></td><br>
        </tr>
        <tr>
         <td>Email :</td> <td><input type="text" name="email"></td><br>
        </tr>
        <tr>
         <td>Password :</td> <td><input type="password" name="pwd"></td><br>
        </tr>
        <tr>
         <td>Confirm Password :</td> <td><input type="password" name="cpwd"><br>
        </tr>
        <tr>
         <td><input type="submit" value="Submit"></td>
        </tr>
       </table>
      </form>
</body>

Css Code:

    body
{
    background-color : #484848;
}
h1
{
    color : #000000;
    text-align : center;
    font-family: "SIMPSON";
}
form
{
    align:"center";
}

How should i change my code to align the entire form in the center?

like image 682
poorvank Avatar asked Sep 30 '13 07:09

poorvank


People also ask

How do I center a form in CSS page?

If you want to do a horizontal centering, just put the form inside a DIV tag and apply align="center" attribute to it. So even if the form width is changed, your centering will remain the same.

How do I center align a form in HTML?

The <center> tag in HTML is used to set the alignment of text into the center.

How do you center align a form in CSS w3schools?

Center Align Elements To horizontally center a block element (like <div>), use margin: auto; Setting the width of the element will prevent it from stretching out to the edges of its container.


2 Answers

Like this

demo

css

    body {
    background-color : #484848;
    margin: 0;
    padding: 0;
}
h1 {
    color : #000000;
    text-align : center;
    font-family: "SIMPSON";
}
form {
    width: 300px;
    margin: 0 auto;
}
like image 181
Falguni Panchal Avatar answered Oct 05 '22 16:10

Falguni Panchal


This is my answer. I'm not a Pro. I hope this answer may help you :3

<div align="center">
<form>
.
.
Your elements
.
.
</form>
</div>
like image 45
Puvipavan Avatar answered Oct 05 '22 18:10

Puvipavan