Align the elements of <input> tag to center on HTML
Find out how to align the element of the input tag to center on the html page using inline style and css.
In this article, we will learn how to center align the elements of the input tag in html.
Usually, when we type anything in an input field on an HTML page, it is left-aligned.

Now, to align the text to the center in the input field, we can do this simple CSS style.
<u>Using inline style</u>
<form> <input style="text-align: center;" type="text" placeholder="Enter your name" /> </form>
<u>Using style.css file</u>
If you want to add text-align: center to all the text fields on your HTML form, then inline styling becomes repetitive work. Instead, we can target all the input filed in our CSS file using a class name.
Example:
<form> <input type="text" class="form-input" placeholder="Enter your name" /> </form>
Here, we have added a class name (form-input) to the input field and then added the style in our css file like this.
.form-input { text-align: center; }
And that's it, this is how you can center the alignment of the elements in your input field on your html page.
Related Posts
How to change the color of <hr> tag using CSS
Here we will learn how to change the color or the background color of HR element in out html using css style.
Check if a HTML checkbox is checked using JavaScript
Find out how to check if the checkbox is checked or not using JavaScript.
Horizontal scrolling div with arrows using HTML and CSS
Tutorial on how to make horizontal scrolling div with arrows using html and css and for smooth scrolling we will use scrollBy() function in Javascript.
What is insertAdjacentHTML() ? How to use it?
Tutorial on Javascript insertAdjacentHTML() method and how can we use it to insert html elements to specific position in our HTML page.
