How to create a stacked form with CSS?

In a stacked form, the input fields, labels and buttons are stacked on top of each other. When the web page with a form is opened on different devices, then it stacks. A form is created on a web page using the

element. Let us see how to create a stacked form with CSS.

Create a form

The form on a web page is created using the

element. The input fields include input type text, password, and repeat password. With that, the signin and register buttons are also positioned ?


By creating an account you agree to our Terms & Privacy.

Style the form

The form is styled using the max-width property to set the maximum width ?

form {
   padding: 16px;
   max-width: 800px;
   margin-left: 20%;
   background-color: rgb(255, 254, 195);
}

Style the input fields

The width for the input fields are set to 100%. The display property is set to inline-block ?

input[type=text], input[type=password] {
   width: 100%;
   font-size: 20px;
   padding: 15px;
   margin: 5px 0 22px 0;
   display: inline-block;
   border: none;
   background: #f1f1f1;
}

The Register button

The


Style the register button ?

.registerbtn {
   background-color: #4CAF50;
   color: white;
   font-size: 25px;
   padding: 16px 20px;
   margin: 8px 0;
   border: none;
   cursor: pointer;
   width: 100%;
   opacity: 0.9;
}

Example

The following is the code to create a stacked form with CSS ?




   


   

Stacked Form Example


By creating an account you agree to our Terms & Privacy.

Updated on: 2023-12-14T12:12:23+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements