DEV Community

Cover image for HOW TO CREATE ICON INPUT ELEMENT USING HTML AND CSS
Mushfiqur Rahman Shishir
Mushfiqur Rahman Shishir

Posted on • Edited on

1

HOW TO CREATE ICON INPUT ELEMENT USING HTML AND CSS

There is a lot of time we need to customize input control. In this post, we are going to create a customized input-element with an icon before it. We will do it using only HTML and CSS.

We are going to use a div element as a container for the input element. Inside our container, we will put the input element and our icon container. The icon container is also a div element. Here is our HTML:

<div class="icon-input-container">
    <input class="icon-input" type="text" placeholder="Email">
    <div class="icon-container">
      <div class="icon-email"></div>
    </div>
</div>
Enter fullscreen mode Exit fullscreen mode

For the icon, we are going to use an SVG. You can get a lot of wonderful icons from FlatIcon for various purposes for free in SVG, PNG and AI format. We have used that SVG as div background. Here is the CSS:

.icon-input {
  width: 100%;
  border: 1px solid #E6E6E6;
  margin: 8px 0;
  outline: none;
  padding: 8px 0px 8px 35px;
  transition: 0.3s;
}

.icon-input-container {
  position: relative;
}

Enter fullscreen mode Exit fullscreen mode

Read The Full Article and Check GitHub Repo.

Thanks for reading and share if you like it.

Sentry image

Make it make sense

Only the context you need to fix your broken code with Sentry.

Start debugging →

Top comments (0)

Image of PulumiUP 2025

From Cloud to Platforms: What Top Engineers Are Doing Differently

Hear insights from industry leaders about the current state and future of cloud and IaC, platform engineering, and security.

Save Your Spot

👋 Kindness is contagious

Explore this insightful post in the vibrant DEV Community. Developers from all walks of life are invited to contribute and elevate our shared know-how.

A simple "thank you" could lift spirits—leave your kudos in the comments!

On DEV, passing on wisdom paves our way and unites us. Enjoyed this piece? A brief note of thanks to the writer goes a long way.

Okay