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 vertically center an icon in an input?

I don’t know how to center an icon vertically inside an input. This is my code:

<i-feather name="user" class="fea icon-sm icons"></i-feather>
<input type="text" class="form-control ps-5" placeholder="Name" name="s" required="">

Currently it looks like this:

HTML input with icon slightly below vertical center

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

and I want to achieve an effect like this:

HTML input with icon centered vertically

How do I center the icon vertically in the input?

>Solution :

You can do it like this:

<style>
.input-wrapper {
  display: flex;
  position: relative;
}

.input-wrapper .icon {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  padding: 0 10px;
}

.input-wrapper input {
  padding: 0 0 0 25px;
  height: 50px;
}
</style>

<div class="input-wrapper">
  <i class="icon">2</i>
  <input type="text" class="form-control ps-5" placeholder="Name" name="s" required="">
</div>
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