Hello developers, today in this blog you'll learn to create an Animated Search Bar using HTML, CSS & JavaScript.
A search box is the most important graphical element present in many desktop applications and websites. It acts as the field for a query input or search term from the user to search and retrieve related information from the database. A search bar icon is used on all websites. To search anything on the website, not only to search in the website.
In this blog (Animated Search Bar), at first, on the website, there is only a search icon at the center of the webpage and when you click on that search bar icon, then the search input appears with an elastic animation. When you type something and click on the search icon, you will be redirected to the page, which contains the data that you search for at the bottom of the search bar. There is also a close icon and when you click on the cancel icon, the visible search input and your typed data will be hidden.
The source code of this Animated Search Bar is given below, if you want the source code of this program, you can copy it. You can use this Animated Search Bar code with your creativity and can take this project to the next level.
Animated Search Bar[Source Code]
To make this website (Animated Search Bar), you need to create three files: an HTML file, a CSS file, and a JavaScript file. First, create an HTML file with the name of index.html and remember, you have to create a file with a .html extension.
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>Animated Search Box || learningrobo</title>
<link rel="stylesheet" href="./style.css">
</head>
<body>
<div class="search-wrapper">
<div class="input-holder">
<input type="text" class="search-input" placeholder="Type to search" />
<button class="search-icon" onclick="searchToggle(this, event);"><span></span></button>
</div>
<span class="close" onclick="searchToggle(this, event);"></span>
</div>
<div class="credit">Made with <span style="color:tomato;font-size:20px;">❤</span> by <a href="https://www.learningrobo.com/">Learning Robo</a></div>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js'></script>
<script src="./script.js"></script>
</body>
</html>
CSS provides style to an HTML page. To make the page attractive create a CSS file with the name style.css and remember that you have to create a file with a .css extension.
JavaScript makes the page work functionally. At last, create a JavaScript file with the name of script.js and remember that you've got need to make a file with a .js extension.
We hope you would like this Animated Search Bar using HTML, CSS & JavaScript.
Thank you for reading our blog. If you face any problem in creating this Animated Search Bar using HTML, CSS & JavaScript, then contact us or comment us. We’ll try to provide a solution to your problem as soon as possible.
A search box is the most important graphical element present in many desktop applications and websites. It acts as the field for a query input or search term from the user to search and retrieve related information from the database. A search bar icon is used on all websites. To search anything on the website, not only to search in the website.
In this blog (Animated Search Bar), at first, on the website, there is only a search icon at the center of the webpage and when you click on that search bar icon, then the search input appears with an elastic animation. When you type something and click on the search icon, you will be redirected to the page, which contains the data that you search for at the bottom of the search bar. There is also a close icon and when you click on the cancel icon, the visible search input and your typed data will be hidden.
The source code of this Animated Search Bar is given below, if you want the source code of this program, you can copy it. You can use this Animated Search Bar code with your creativity and can take this project to the next level.
Animated Search Bar[Source Code]
To make this website (Animated Search Bar), you need to create three files: an HTML file, a CSS file, and a JavaScript file. First, create an HTML file with the name of index.html and remember, you have to create a file with a .html extension.
body {
background-color: #FAD961;
background-image: linear-gradient(90deg, #FAD961 0%, #F76B1C 100%);
}
::selection {
background: #212129;
}
.search-wrapper {
position: absolute;
transform: translate(-50%, -50%);
top:50%;
left:50%;
}
.search-wrapper.active {}
.search-wrapper .input-holder {
height: 70px;
width:70px;
overflow: hidden;
background: rgba(255,255,255,0);
border-radius:6px;
position: relative;
transition: all 0.3s ease-in-out;
}
.search-wrapper.active .input-holder {
width:450px;
border-radius: 50px;
background: #12192c;
transition: all .5s cubic-bezier(0.000, 0.105, 0.035, 1.570);
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19)
}
.search-wrapper .input-holder .search-input {
width:100%;
height: 50px;
padding:0px 70px 0 20px;
opacity: 0;
position: absolute;
top:0px;
left:0px;
background: transparent;
box-sizing: border-box;
border:none;
outline:none;
font-family:"Open Sans", Arial, Verdana;
font-size: 16px;
font-weight: 400;
line-height: 20px;
color:#FFF;
transform: translate(0, 60px);
transition: all .3s cubic-bezier(0.000, 0.105, 0.035, 1.570);
transition-delay: 0.3s;
}
.search-wrapper.active .input-holder .search-input {
opacity: 1;
transform: translate(0, 10px);
}
.search-wrapper .input-holder .search-icon {
width:70px;
height:70px;
border:none;
border-radius:50px;
background: #12192c;
padding:0px;
outline:none;
position: relative;
z-index: 2;
float:right;
cursor: pointer;
transition: all 0.3s ease-in-out;
}
.search-wrapper.active .input-holder .search-icon {
width: 50px;
height:50px;
margin: 10px;
border-radius: 30px;
background-color: #FAD961;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19)
}
.search-wrapper .input-holder .search-icon span {
width:22px;
height:22px;
display: inline-block;
vertical-align: middle;
position:relative;
transform: rotate(45deg);
transition: all .4s cubic-bezier(0.650, -0.600, 0.240, 1.650);
}
.search-wrapper.active .input-holder .search-icon span {
transform: rotate(-45deg);
}
.search-wrapper .input-holder .search-icon span::before, .search-wrapper .input-holder .search-icon span::after {
position: absolute;
content:'';
}
.search-wrapper .input-holder .search-icon span::before {
width: 4px;
height: 11px;
left: 9px;
top: 18px;
border-radius: 50px;
background: #F76B1C;
}
.search-wrapper .input-holder .search-icon span::after {
width: 14px;
height: 14px;
left: 0px;
top: 0px;
border-radius: 50px;
border: 4px solid #F76B1C;
}
.search-wrapper .close {
position: absolute;
z-index: 1;
top:24px;
right:20px;
width:25px;
height:25px;
cursor: pointer;
transform: rotate(-180deg);
transition: all .3s cubic-bezier(0.285, -0.450, 0.935, 0.110);
transition-delay: 0.2s;
}
.search-wrapper.active .close {
right:-50px;
transform: rotate(45deg);
transition: all .6s cubic-bezier(0.000, 0.105, 0.035, 1.570);
transition-delay: 0.5s;
}
.search-wrapper .close::before, .search-wrapper .close::after {
position:absolute;
content:'';
background: #12192c;
border-radius: 2px;
}
.search-wrapper .close::before {
width: 5px;
height: 25px;
left: 10px;
top: 0px;
}
.search-wrapper .close::after {
width: 25px;
height: 5px;
left: 0px;
top: 10px;
}
.credit a{
text-decoration: none;
color: #000;
font-weight: 800;
}
.credit {
font-family: Verdana, Geneva, Tahoma, sans-serif;
position: fixed;
bottom:20px;
left:40%;
margin-top: 10px;
}
function searchToggle(obj, evt){
var container = $(obj).closest('.search-wrapper');
if(!container.hasClass('active')){
container.addClass('active');
evt.preventDefault();
}
else if(container.hasClass('active') && $(obj).closest('.input-holder').length == 0){
container.removeClass('active');
container.find('.search-input').val('');
}
}
Thank you for reading our blog. If you face any problem in creating this Animated Search Bar using HTML, CSS & JavaScript, then contact us or comment us. We’ll try to provide a solution to your problem as soon as possible.
Post a Comment
Thank you
Learning robo team