A well-designed search bar is essential for improving user experience on any website. This tutorial will walk you through a modern, minimalist, and fully responsive search input field using HTML, CSS, and Google Fonts.
<html lang="en">
<head>
<meta charset="UTF-8" />
<style>
/* Google Fonts - Poppins */
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600&display=swap");
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Poppins", sans-serif;
}
.input-box {
position: relative;
height: 76px;
max-width: 900px;
width: 100%;
background: #fff;
margin: 20px;
border-radius: 8px;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
}
.input-box i,
.input-box .button {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
.input-box i {
left: 20px;
font-size: 30px;
color: #707070;
}
.input-box input {
height: 100%;
width: 100%;
outline: none;
font-size: 18px;
font-weight: 400;
border: none;
padding: 0 155px 0 65px;
background-color: transparent;
}
.input-box button {
right: 20px;
font-size: 16px;
font-weight: 400;
color: #fff;
border: none;
padding: 12px 30px;
border-radius: 6px;
background-color: #4070f4;
cursor: pointer;
}
.input-box button:active {
transform: translateY(-50%) scale(0.98);
}
/* Responsive */
@media screen and (max-width: 500px) {
.input-box {
height: 66px;
margin: 0 8px;
}
.input-box i {
left: 12px;
font-size: 25px;
}
.input-box input {
padding: 0 112px 0 50px;
}
.input-box button {
right: 12px;
font-size: 14px;
padding: 8px 18px;
}
}
</style>
<link rel="stylesheet" href="https://unicons.iconscout.com/release/v4.0.0/css/line.css" />
</head>
<body>
<form action="https://www.hamrocolleges.com" method="get" class="search-bar">
<div class="input-box">
<i class="uil uil-search"></i>
<input type="text" placeholder="Search" name="s" />
<button class="button" id="searchButton">Search</button>
</div>
</form>
</body>
</html>
The code consists of three main parts:
The HTML structure creates a form with a search input box and a button.
<form action="https://www.hamrocolleges.com" method="get" class="search-bar">
<div class="input-box">
<i class="uil uil-search"></i>
<input type="text" placeholder="Search" name="s" />
<button class="button" id="searchButton">Search</button>
</div>
</form>
<form>
tag specifies the action URL and the GET method for passing query parameters.<div class="input-box">
wraps the input field, search icon, and button.<i class="uil uil-search"></i>
is the icon for the search bar, provided by the Unicons library.<input>
creates the text field for search queries.<button>
provides the clickable “Search” functionality.The CSS brings the design to life with a clean, responsive layout.
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600&display=swap");
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Poppins", sans-serif;
}
*
resets margins, paddings, and enables consistent sizing..input-box {
position: relative;
height: 76px;
max-width: 900px;
width: 100%;
background: #fff;
margin: 20px;
border-radius: 8px;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
}
.input-box i {
position: absolute;
left: 20px;
top: 50%;
transform: translateY(-50%);
font-size: 30px;
color: #707070;
}
.input-box input {
height: 100%;
width: 100%;
outline: none;
font-size: 18px;
font-weight: 400;
border: none;
padding: 0 155px 0 65px;
background-color: transparent;
}
.input-box
creates a visually appealing container with rounded corners and a shadow for depth..input-box button {
position: absolute;
right: 20px;
top: 50%;
transform: translateY(-50%);
font-size: 16px;
font-weight: 400;
color: #fff;
border: none;
padding: 12px 30px;
border-radius: 6px;
background-color: #4070f4;
cursor: pointer;
}
.input-box button:active {
transform: translateY(-50%) scale(0.98);
}
The responsive design ensures usability on smaller devices.
@media screen and (max-width: 500px) {
.input-box {
height: 66px;
margin: 0 8px;
}
.input-box i {
left: 12px;
font-size: 25px;
}
.input-box input {
padding: 0 112px 0 50px;
}
.input-box button {
right: 12px;
font-size: 14px;
padding: 8px 18px;
}
}