Bootstrap input clear button example
June 23, 2022Hi Friends 👋,
Welcome To aGuideHub! ❤️
To make input clear button, put the type="search"
attribute to create an input clear button in bootstrap for example.
Today, I am going to show you. how to create input clear button in bootstrap with code example.
Table of contents
- Includes bootstrap view
- Includes bootstrap library
- Define its attribute name
This article will guide you to adding input clear button in Bootstrap 4 with example.
Step 1: Includes bootstrap view
To ensure proper rendering and touch zooming for all devices, add the responsive viewport meta tag to your <head>
.
<meta name="viewport" content="width=device-width, initial-scale=1">
Step : Includes bootstrap library
First of all, load the Bootstrap 4 framework CSS into the head tag of your webpage.
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css"
integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
</head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
Step 3: Define its attribute name
After that, create the input clear button with a attribute name .<input type="search">
.
<h3 class="text-center">Bootstrap Input Clear Button</h3>
<div class="container">
<div class="input-group search-style ">
<input id="Search" class="form-control border-secondary py-2 " type="search" placeholder="search"
style="border-right: none !important;">
<div class="input-group-append">
<button class="btn removefocus" type="button" style="border-top: 1px solid gray;
border-right: 1px solid gray;
border-bottom: 1px solid gray;">
<i class="fa fa-search "></i>
</button>
</div>
</div>
</div>
Example.
Let’s look at the following example to understand how it basically works:
input-clear-button-in-bootstrap.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css"
integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
</head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<h3 class="text-center">Bootstrap Input Clear Button</h3>
<div class="container">
<div class="input-group search-style ">
<input id="Search" class="form-control border-secondary py-2 " type="search" placeholder="search"
style="border-right: none !important;">
<div class="input-group-append">
<button class="btn removefocus" type="button" style="border-top: 1px solid gray;
border-right: 1px solid gray;
border-bottom: 1px solid gray;">
<i class="fa fa-search "></i>
</button>
</div>
</div>
</div>
</body>
</html>
Check the output of the above code example.
All the best 👍