- How to Add Search Icon in Input field Using HTML and CSS
- Search Icon Html Code:-
- CSS Search Bar With Icon Inside:-
- How to Add Search Icon in Input field Using HTML and CSS
- Css Search Bar With Icon Inside:-
- How To Make 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.
- Add the input box inside the tag.
- Download a search icon.
- Step 4: Add a div with the image icon inside.
- Add the magical CSS
- Download Source Code
- Online Resources
- Share our tutorial
How to Add Search Icon in Input field Using HTML and CSS
Hello Coder! A very warm welcome to the Codewithrandom blog. Today we are Going to Learn How to Add a Search Icon in the Input field Using HTML and CSS Code. In this, we are making Search Icons inside the input box with icons that look beautiful, and this box is used for looking the website more responsive. So. Let’s start creating a search icon inside the input field. You can see the live server of this project.
Search Icon Html Code:-
In HTML we create the basic layout of the website. Here we are using the same basic concepts of HTML like div, span, classes, ids, button,s and input tags. Input tag:- (default value) So here we want to give input as text so we are choosing the input type as text. The tag specifies an input field where the user can enter data. The element is the most important form element. The b element can be displayed in several ways, depending on the type attribute. (default value) For the search icon we are using FontAwesome CDN(Content-Delivery-Network). Instead of Font-Awesome, you can use several other websites/CDN for inserting icons into your website like Bootstrap icons, Ionicons, Boxicons, etc.
CSS Search Bar With Icon Inside:-
As you have seen HTML output is ready still it looks so unorganized and awful. So we need to decorate/style it using CSS or CSS frameworks like Bootstrap5, Tailwind, SCSS or SASS, etc.
But here we are using only Pure CSS and Bootstrap 5 for styling it. What is Bootstrap? Bootstrap is a free and open-source CSS framework directed at responsive, mobile-first front-end web development. It contains HTML, CSS, and JavaScript-based design templates for typography, forms, buttons, navigation, and other interface components. So you can integrate Bootstrap with your website by either you can install Bootstrap locally in your system or you can integrate bootstrap with your codebase using CDN(Content-Delivery-Network). After integrating the bootstrap with your code for its usage you have to read the Documentation. What is Position? The position property specifies the type of positioning method used for an element (static, relative, fixed, absolute, or sticky).The position property specifies the type of positioning method used for an element. There are five different position values:
static
relative
fixed
absolute
sticky Elements are then positioned using the top, bottom, left, and right properties. However, these properties will not work unless the position property is set first. They also work differently depending on the position value. We have to use only the relative and absolute position here so we are going to discuss it. position: relative; An element with position: relative; is positioned relative to its normal position. Setting the top, right, bottom, and left properties of a relatively-positioned element will cause it to be adjusted away from its normal position. Other content will not be adjusted to fit into any gap left by the element. position: absolute; An element with position: absolute; is positioned relative to the nearest positioned ancestor (instead of positioned relative to the viewport, like fixed). However; if an absolute positioned element has no positioned ancestors, it uses the document body, and moves along with page scrolling. Note: Absolute positioned elements are removed from the normal flow, and can overlap elements.
/* Styles for wrapping the search box */ .main < width: 50%; margin: 50px auto; >/* Bootstrap 5 text input with search icon */ .has-search .form-control < padding-left: 2.375rem; >.has-search .form-control-feedback
Finally, you’re How to Add Search Icon in the Input field Using HTML and CSS IS DONE. You can Search inside this box. the position of the icon is inside the box. If you like this blog or have any doubts comment in the comment box. thankyou. WRITTEN- BY_SAYALI KHARAT & Himanshu Singh
How to Add Search Icon in Input field Using HTML and CSS
If yes, then here is our Master Frontend: Zero to Hero eBook! 📚 In this eBook, you’ll learn complete HTML, CSS, Bootstrap, and JavaScript from beginner to advance level. 💪 It includes 450 Projects with source code.
So here we want to give input as text so we are choosing the input type as text.
The tag specifies an input field where the user can enter data.
The element is the most important form element.
The b element can be displayed in several ways, depending on the type attribute.
For the search icon we are using FontAwesome CDN(Content-Delivery-Network). Instead of Font-Awesome, you can use several other websites/CDN for inserting icons into your website like Bootstrap icons, Ionicons, Boxicons, etc.
Css Search Bar With Icon Inside:-
As you have seen HTML output is ready still it looks so unorganized and awful. So we need to decorate/style it using CSS or CSS frameworks like Bootstrap5, Tailwind, SCSS or SASS, etc.
But here we are using only Pure CSS and Bootstrap 5 for styling it.
What is Bootstrap?
Bootstrap is a free and open-source CSS framework directed at responsive, mobile-first front-end web development. It contains HTML, CSS, and JavaScript-based design templates for typography, forms, buttons, navigation, and other interface components.
So you can integrate Bootstrap with your website by either you can install Bootstrap locally in your system or you can integrate bootstrap with your codebase using CDN(Content-Delivery-Network). After integrating the bootstrap with your code for its usage you have to read the Documentation.
What is Position?
The position property specifies the type of positioning method used for an element (static, relative, fixed, absolute, or sticky).The position property specifies the type of positioning method used for an element.
There are five different position values:
static
relative
fixed
absolute
sticky
Elements are then positioned using the top, bottom, left, and right properties. However, these properties will not work unless the position property is set first. They also work differently depending on the position value.
We have to use only the relative and absolute position here so we are going to discuss it.
position: relative;
An element with position: relative; is positioned relative to its normal position.
Setting the top, right, bottom, and left properties of a relatively-positioned element will cause it to be adjusted away from its normal position. Other content will not be adjusted to fit into any gap left by the element.
position: absolute;
An element with position: absolute; is positioned relative to the nearest positioned ancestor (instead of positioned relative to the viewport, like fixed).
However; if an absolute positioned element has no positioned ancestors, it uses the document body, and moves along with page scrolling.
Note: Absolute positioned elements are removed from the normal flow, and can overlap elements.
/* Styles for wrapping the search box */ .main < width: 50%; margin: 50px auto; >/* Bootstrap 5 text input with search icon */ .has-search .form-control < padding-left: 2.375rem; >.has-search .form-control-feedback
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.
Step by Step HTML and CSS Search Box Guide
Create the index.html with its basic structure.
Add the input box inside the tag.
Also include the placeholder saying «Search. » and an ID of «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.
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.
#search-text-input < border-top:thin solid #e5e5e5; border-right:thin solid #e5e5e5; border-bottom:0; border-left:thin solid #e5e5e5; box-shadow:0px 1px 1px 1px #e5e5e5; float:left; height:17px; margin:.8em 0 0 .5em; outline:0; padding:.4em 0 .4em .6em; width:183px; >#button-holder < background-color:#f1f1f1; border-top:thin solid #e5e5e5; box-shadow:1px 1px 1px 1px #e5e5e5; cursor:pointer; float:left; height:27px; margin:11px 0 0 0; text-align:center; width:50px; >#button-holder img
Download Source Code
You can download all the code used in this tutorial for only $9.99 $5.55!
[purchase_link text=»Download Now» style=»button» color=»green»]Online Resources
You can also use the following resources for other techniques in doing this task.
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. 🙂
Share our tutorial
- Click to share on LinkedIn (Opens in new window)
- Click to share on Twitter (Opens in new window)
- Click to share on Facebook (Opens in new window)
- Click to share on Pocket (Opens in new window)
- Click to share on Reddit (Opens in new window)
- Click to email a link to a friend (Opens in new window)
- Click to share on Telegram (Opens in new window)
- Click to share on WhatsApp (Opens in new window)
- Click to share on Skype (Opens in new window)
- Click to print (Opens in new window)
- Click to share on Tumblr (Opens in new window)