Last updated: November 30, 2026. Added a short direct answer, definitions of key terms and a comparison table.
In this article, we will see how to create a custom search bar using HTML and CSS. The custom search bar will look like this. If you are not into coding, you can add the following search for sites that make it easy to integrate site search in your website.
To create a custom search bar, add a form with the class search-container that holds a text input with the id search-bar and a linked search icon image. Then style it with CSS: a 490px container, a 45px input height, and a #008ABF focus border. The code adds only a search box, so it cannot search yet.
Steps to add HTML custom search
- Add custom search HTML-
The form element with the class search-container wraps the whole search bar. The input type=”text” element collects the query, and its placeholder attribute shows the hint text “What can I help you with today?”. The anchor wrapping the img element is the clickable search icon, placed beside the input inside the same form.
<body> <form class="search-container"> <input type="text" id="search-bar" placeholder="What can I help you with today?"> <a href="#"><img class="search-icon" src="https://blog.expertrec.com/search-icon-1/"></a> </form> </body> - Add custom search CSS-
body{ padding-top: 75px; } .search-container{ width: 490px; display: block; margin: 0 auto; } input#search-bar{ margin: 0 auto; width: 100%; height: 45px; padding: 0 20px; font-size: 0.75rem; border: 1px solid orange; outline: none; &:focus{ border: 1px solid #008ABF; transition: 0.35s ease; color: #008ABF; &::-webkit-input-placeholder{ transition: opacity 0.45s ease; opacity: 0; } &::-moz-placeholder { transition: opacity 0.45s ease; opacity: 0; } &:-ms-placeholder { transition: opacity 0.45s ease; opacity: 0; } } } .search-icon{ position: relative; float: right; width: 75px; height: 75px; top: -62px; right: -45px; }
The above code, adds just a search box. (meaning you cant search using it). Create your custom search bar, go here.
Key CSS selectors and values
| Selector | Property | Value |
|---|---|---|
| .search-container | width | 490px |
| input#search-bar | height | 45px |
| input#search-bar | width | 100% |
| input#search-bar:focus | border | 1px solid #008ABF |
| .search-icon | width | 75px |
| .search-icon | height | 75px |
What the main input values control
- padding: 0 20px sets the inner text spacing.
- font-size: 0.75rem sets the text size.
- border: 1px solid orange sets the default border.
- transition: 0.35s ease animates the border change on focus.





