How to Insert a Search Icon in Bootstrap ?
Last Updated :
08 May, 2023
In this article, we will see how to insert a search icon in Bootstrap. While Bootstrap does not include an icon set by default, they do have their own comprehensive icon library called Bootstrap Icons. Feel free to use them or any other icon set in your project. There are various ways to add a search icon or other icons to your HTML page. All the icons in the icon libraries can be customized with CSS (size, align, rotate, shadow, color, etc.).
There are two methods:
Method 1: Using bootstrap Glyphicons: Bootstrap gives us various predefined icons including search icons. You can add various types of icons from https://glyphicons.com/.
Step-by-step guide for the implementation:
Step 1: Include Bootstrap and jQuery CDN into the <head> tag before all other stylesheets to load our CSS.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
Step 2: Add <div> tag in the HTML body with the class container.
Step 3: Now add any icon that you want using the below syntax, where the name is the name of glyphicon.
<span class="glyphicon glyphicon-name"></span>
Example: The following example shows different types of glyphicons and their usage.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet"
href=
"https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<script src=
"https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js">
</script>
</head>
<body>
<div class="container">
<h2 style="color:green">Glyphicons Examples</h2>
<p>Camera icon:
<span class="glyphicon glyphicon-camera"></span>
</p>
<p>Search icon:<span class="glyphicon glyphicon-search"></span></p>
<p>Search icon on a button:
<button type="button" class="btn btn-default">
<span class="glyphicon
glyphicon-search"></span> Search
</button>
</p>
<p>Bell icon:
<span class="glyphicon glyphicon-bell"></span>
</p>
</div>
</body>
</html>
Output:
All glyphicons
Method 2 Using font awesome icons: Font Awesome is a web font containing all the icons from the Twitter Bootstrap framework. Font Awesome is a widely-used icon set that gives you scalable vector images that can be customized with CSS.
Step-by-step guide for the implementation:
Step 1: Copy your kit's code into the <head> of each template or page in your project where you want to use Font Awesome via the kit. If you've got other versions or flavors of Font Awesome already in use, make sure to remove them.
<script src="https://kit.fontawesome.com/6ec9c7cfba.js" crossorigin="anonymous"></script>
Step 2: Add any free icons to a project with one line of code.
Syntax:
<i class="fas fa-camera"></i>
<i class="fas fa-camera"></i>
<span class="fas fa-camera"></span>
Example: The following example shows different types of font-awesome icons including search icon and their usage.
HTML
<!DOCTYPE>
<html>
<head>
<script src="https://kit.fontawesome.com/6ec9c7cfba.js"
crossorigin="anonymous">
</script>
</head>
<body>
<h1 style="color:green">
GeeksforGeeks
</h1>
<i class="fas fa-chess" style="font-size:32px;"></i>
<i class="fas fa-biking" style="font-size:42px;"></i>
<i class="fas fa-bacteria" style="font-size:52px;"></i>
<i class="fa fa-car" style="font-size:62px;"></i>
<p style="color:green">Search icon
<i class="fas fa-search" style="font-size:72px;"></i>
</p>
</body>
</html>
Output:
Search icon
Similar Reads
How to use Bootstrap Icons in React ?
React is a free library for making websites look and feel cool. With React, your websites can be super interactive and lively. Itâs great for making modern websites where everything happens on one page. The best part is that you can build and reuse different parts of your webpage, making it easy to
2 min read
How to Add Icon in NavBar using React-Bootstrap ?
This article will show you how to add an icon in the navigation bar using React-Bootstrap. We will use React-Bootstrap because it makes it easy to use reusable components without implementing them. PrerequisitesReactJSJSXReact BootstrapCreating React App and Installing ModuleStep 1: Create a React a
2 min read
How to Style Icons Bold in Bootstrap ?
An icon is a visual representation that helps to understand the website & also helps to navigate through the website. To create a bold icon in CSS, we use font-weight as bold but in Bootstrap this syntax doesn't work. We will learn how to style icons bold in bootstrap in this article.Using CSS c
2 min read
How to Add MUI React Button Icon in React-Bootstrap ?
In this article, we will learn how to add the mui react button icon in react-bootstrap. Icons can be added in the react-bootstrap by importing the MUI icon component and using it within your React-Bootstrap button. React-Bootstrap is a front-end framework that was designed keeping React in mind. Ste
2 min read
How To Use Bootstrap Icons In Angular?
The most popular framework for making responsive and mobile-friendly websites is called Bootstrap. They include forms, typography, buttons, tables, navigation, modals, and picture carousels etc.These are built using CSS and HTML. It also supports plugins written in JavaScript. It provides the proces
3 min read
How to add icons in project using Bootstrap ?
Bootstrap Icons is an open-source icon library specifically designed for use with Bootstrap's framework. Adding icons using Bootstrap means integrating the Bootstrap Icons library into your project and using its icon classes in HTML. This allows easy inclusion of scalable, customizable icons directl
2 min read
How to add dropdown search bar in Bootstrap?
A dropdown search bar in Bootstrap combines a text input field with a dropdown menu, providing users with options to select from while allowing them to input custom search queries. It enhances user experience by offering both flexibility and convenience.Preview of final output: Let us have a look at
2 min read
How to install Bootstrap 5?
Bootstrap 5, a popular front-end framework, empowers developers to create sleek and responsive websites with minimal effort. To install Bootstrap 5, you can choose from three methods including CDN links for quick integration, employ package managers like npm for seamless dependency management, or ma
5 min read
How to add Icons to Buttons in Bootstrap 5 ?
Adding Icons to the buttons enhances the overall look of the web page. Buttons are the components provided to create various buttons. Bootstrap 5 includes several predefined button styles, each serving its purpose. We can add icons to the buttons in several ways including Font Awesome Icons and Icon
2 min read
How to Add Bootstrap in a Project?
Bootstrap is a popular open-source framework for building responsive and mobile-first websites using HTML, CSS, and JavaScript. It provides pre-designed components and templates that simplify web development. Why Use Bootstrap?Bootstrap offers several advantages for web development:Faster and Easier
3 min read