We can use labels to display short text beside other components.
To display a label, you need to add a label class to inline HTML elements such as
span
and i
.
Here, we'll use a span to show a label beside an h3
element:
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
</head><!--from w ww. java 2 s . c om-->
<body style='margin:30px'>
<h3>Jump Start Bootstrap <span class="label label-default"> tutorial.</span></h3>
</body>
</html>
The available label variants are:
<!-- ww w.j a v a 2s . c o m-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example of Twitter Bootstrap 3 Inline Labels</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<style type="text/css">
.bs-example{
margin: 20px;
}
</style>
</head>
<body>
<div class="bs-example">
<p>This is a <span class="label label-default">Default</span> label.</p>
<p>This is a <span class="label label-primary">Primary</span> label.</p>
<p>This is a <span class="label label-success">Success</span> label.</p>
<p>This is an <span class="label label-info">Info</span> label.</p>
<p>This is an <span class="label label-warning">Warning</span> label.</p>
<p>This is an <span class="label label-danger">Danger</span> label.</p>
</div>
</body>
</html>
We can use badges to display the number of unread messages.
<!-- www . j a v a 2s. com-->
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<style type="text/css">
.bs-example{
margin: 20px;
}
</style>
</head>
<body>
<div class="bs-example">
<ul class="nav nav-pills">
<li><a href="#">Home</a></li>
<li><a href="#">Profile</a></li>
<li class="active"><a href="#">Messages <span class="badge">24</span></a></li>
<li><a href="#">Email <span class="badge">5</span></a></li>
</ul>
</div>
</body>
</html>