top of page
Writer's pictureWeb Coding

How to create a search bar

Today I will be teaching you how to create a search bar for your website using only HTML and CSS


HTML

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title>Document</title>
 <link rel="stylesheet" href="style.css">
</head>
<body>
 <div id="content">
 <input type="text" name="search" id="search" placeholder="Search">
 <button type="button" id="searchButton"></button>
 </div>
</body>
</html>

CSS

*{
 padding0;
 margin0;
}

body{
 height100vh;
 displayflex;
 align-itemscenter;
 justify-contentcenter;
 backgroundlinear-gradient(to right#cb2d3e#ef473a);
}

div{
 displayflex;
 justify-contentcenter;
 align-itemscenter;
 height4vw;
 width45 vw;
 background-colorblack;
 border-radius45px;
 background-colorrgba(0000.7);
}

#search{
 height3vw;
 font-size2vh;
 bordernone;
 width42vw;
 background-colorrgba(0000);
 outlinenone;
 colorwhite;
 padding-left2vh;
}

#searchButton{
 height3vw;
 width3vw;
 margin-right0.7vw;
 background-imageurl(images/icons8-search.svg), linear-gradient(to right#cb2d3e#ef473a);
 background-sizecover;
 background-repeatno-repeat;
 outlinenone;
 cursorpointer;
 bordernone;
 border-radius90px;
}

#searchButton:hover{
 opacity0.7;
}

If you found this blog post helpful don’t forget to check out my other projects and if you want more content follow me on


YouTube: https://www.youtube.com/channel/UC2nxqB2usQIS2c8zwVZKWEQ

Instagram: https://www.instagram.com/coding_for_the_web/

Twitter: https://twitter.com/LearnWebCoding

7 views

Comments


bottom of page