In this tutorial, you will learn how to make Expanding Search Bar. Earlier I discussed many types of search bars. This search box is simple but smart. Only HTML and CSS are used here.
This is a CSS Expandable Search Box. Under normal circumstances, the full search bar cannot be found. An icon will be found instead. When you click on that icon, the entire search bar will be expanded.
This type of Expanding Search Bar is now used on almost all websites. This type of bar can be made in many ways. In some cases, the bar can be seen by clicking on the icon. In some cases, it can be seen only by hovering.
CSS expanding search bar
The design used here is quite simple. If you hover over the icon, you will see the complete search bar. Below is a preview from which you can learn how the expandable search bar works.
See the Pen
Untitled by Foolish Developer (@foolishdevweb)
on CodePen.
As you can see above, a white box has been created on the webpage. There is an icon in that box. If you click on that button, you will see the complete search bar.
How to create an expanding search bar
If you want to download all the code to make it, use the button at the bottom of the article. Although I gave all the code below. Create HTML, and CSS files to copy and use the code.
The following code is HTML. Copy these codes and add them to your HTML file.
#CSS Code (style.css)
The following code is CSS. Copy these codes and add them to your CSS file. Be sure to use the rename style.css of your CSS file.
Here inside our css file using the body tag selector we will set the width and height of the body as 100% and using the background color property we will set the background as “black”.
Using the class selector (single-search) we will set the border radius as 30px and using the margin bottom property we will set the bottom margin to our search button of 30px
Then using the hover property to our button we will use the transform property to scale to expande the length of the search bar on hover.
Conclusion:
If you have difficulty copying your code, use the download button below. If you have any problems with this CSS Expanding Search Bar, please comment.