How To Make TextBox with Search Icon in HTML and CSS?

Search boxes are a common requirement in almost every website you'll create. It is very useful when users want to find certain data, it may have auto complete functions for assisting users to search.

But it this post I'll guide you on how to create an input box or TextBox with search icon in HTML and CSS.

Recently I was asked to create this search box with a style that looks like the YouTube search box. Although not exactly the same as YouTube, I still made it with the same style. This can be useful for you too if you want a search box with decent style instantly.

TextBox with Search Icon in HTML and CSS

Step by Step HTML and CSS Search Box Guide

Create the index.html with its basic structure.

<!doctype html>
        <title>TextBox with Search Icon in HTML and CSS - Tutorial from</title>

Add the input box inside the tag.

Also include the placeholder saying "Search..." and an ID of "search-text-input".

<input type='text' placeholder='Search...' id='search-text-input' />

Download a search icon.

Since we want to have a search box with search icon, download a magnifying glass icons which is a standard icon for search. It must be a transparent PNG icon. Size depends on what you need but in this example we have a 32 x 32 px icon. Put in in the same directory as the index.html.

Step 4: Add a div with the image icon inside.

The "div" tag should have an ID of "button-holder". My magnifying glass icons was named magnifying_glass.png.

<div id='button-holder'>
    <img src='magnifying_glass.png' />

Add the magical CSS

We have three elements with IDs that we should style. Again, you can play or experiment with the CSS to suite your visual needs. I put the code below inside the "head" tag, after the "title" tag.

    border-top:thin solid  #e5e5e5;
    border-right:thin solid #e5e5e5;
    border-left:thin solid  #e5e5e5;
    box-shadow:0px 1px 1px 1px #e5e5e5;
    margin:.8em 0 0 .5em; 
    padding:.4em 0 .4em .6em; 
    border-top:thin solid #e5e5e5;
    box-shadow:1px 1px 1px 1px #e5e5e5;
    margin:11px 0 0 0;
#button-holder img{

Download Source Code

You can download all the code used in this tutorial for only $9.99 $5.55!

[purchase_link id="12487" text="Download Now" style="button" color="green"]

Online Resources

You can also use the following resources for other techniques in doing this task.

How do I create a search button within a textbox?
search icon inside search box
TextBox with Search icon as background image

If you made other TextBox with search icon in HTML and CSS, please let us see it by dropping the demo link on the comments section below, we love to see your own creations! Thanks for visiting and take care. :)

Hi! I'm Mike Dalisay, the co-founder of, a site that helps you build web applications with PHP and JavaScript. Need support? Comment below or contact [email protected]

I'm also passionate about technology and enjoy sharing my experience and learnings online. Connect with me on LinkedIn, Twitter, Facebook, and Instagram.