Bootstrap badge with glyphicon example
May 20, 2022Hi Friends 👋,
Welcome To aGuideHub! ❤️
In this tutorial, we will learn how to create badge with glyphicon in bootstrap.
Badge is a new UI element. It provides users with a visual clue to help them discover additional relevant content.
Table of contents
- Includes bootstrap view
- Includes bootstrap library
- Includes css in html page
- Define its class name
This article will guide you to adding badge with glyphicon in Bootstrap 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 2: Includes bootstrap library
First of all, load the Bootstrap framework CSS into the head tag of your webpage.
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
Step 3: Define its class name
After that, create the badge with glyphicon with a class name .badge glyphicon glyphicon-time
.
<div class="container">
<h3>Bootstrap badge with glyphicon example</h3>
<span class="badge">13434 <span class="glyphicon glyphicon-time"></span></span>
</div>
Step 4: Includes css in html page
Here we will use css to get the badge glyphicon color to the right place.
<style>
.badge > .glyphicon {
background: red;
padding: 5px;
border-radius:50%;
}
</style>
Example.
Let’s look at the following example to understand how it basically works:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
.badge > .glyphicon {
background: red;
padding: 5px;
border-radius:50%;
}
</style>
</head>
<body>
<div class="container">
<h3>Bootstrap badge with glyphicon example</h3>
<span class="badge">13434 <span class="glyphicon glyphicon-time"></span></span>
</div>
</body>
</html>
Check the output of the above code example.
All the best 👍