Align the elements of input tag to center on HTML

featured Image

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.

center align text in input field on html form

Now, to align the text to the center in the input field, we can do this simple CSS style.

Using inline style

<form>
      <input
        style="text-align: center;"
        type="text"
        placeholder="Enter your name"
      />
</form>

Using style.css file

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

featured Image

Disable scrolling Behavior on a body with element on position fixed in mobile

Here in this article, we will learn on how to disable the scroll behavior of the body whenever we scroll over an element whose position is fixed in our mobile…

Read more
featured Image

How to Remove Underline from Links in Bootstrap.

In this article, we will learn how to remove the underline from anchor tags in Bootstrap. Just like any other HTML element, links can also be styled using CSS. We…

Read more
featured Image

How to disable the resizable property of a textarea

In this article, we will see quick ways to disable the resizable property of a textarea using CSS. In CSS, we can disable it using the resize property. Set resize…

Read more