Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I center the "input" tag in CSS?

Im trying to customize "input" in CSS this is code I write:

  input {
    background-color:black;
    border-color: blueviolet;
    outline-color:peru;
    color: crimson;
    height: 50px;
}

And I want to put the "input" tag in the middle.

I tried:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

text-align: center;

but didn’t work

>Solution :

One way you can center an element in its parent container is by making it display: block and setting the margin to auto:

input {
    background-color:black;
    border-color: blueviolet;
    outline-color:peru;
    color: crimson;
    height: 50px;
    margin: auto;
    display: block;
}
<input>

Another could be by using flex-box styling:

body {
    display: flex;
    justify-content: center;
}

input {
    background-color:black;
    border-color: blueviolet;
    outline-color:peru;
    color: crimson;
    height: 50px;
}
<input>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading