How To Create Bootstrap 4 Search Box with Icon
Today, we will learn How To Create a Bootstrap 4 Search Box with Icon. This code snippet helps you to create a Bootstrap 4 search box with an icon. We will use Font Awesome icon inside the text input with the help of this example code. I will give you two examples of How To Create a Bootstrap 4 Search Box with an Icon.
How To Create Bootstrap 4 Search Box with Icon
Example
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>How To Create Bootstrap 4 Search Box with Icon</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<!-- Bootstrap CSS -->
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css'>
<!-- Font Awesome CSS -->
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css'>
<style>
.search .form-control {
padding-left: 2.3rem;
}
.search .search-icon {
position: absolute;
z-index: 2;
display: block;
width: 2.3rem;
height: 2.3rem;
line-height: 2.3rem;
text-align: center;
pointer-events: none;
color: #6c757d;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-12 mt-3">
<h1 class="text-center">How To Create Bootstrap 4 Search Box with Icon</h1>
<div class="form-group search mt-3">
<span class="fa fa-search search-icon"></span>
<input type="text" class="form-control" placeholder="Search...">
</div>
<div class="input-group">
<input type="text" class="form-control" placeholder="Search...">
<div class="input-group-append">
<button class="btn btn-secondary" type="button">
<i class="fa fa-search"></i>
</button>
</div>
</div>
</div>
</div>
</div>
</body>
</html>