Introduction
Bootstrap contains a lot of helper classes that make the life of a front-end developer a lot less tedious by cutting down a lot of redundant CSS and JS. Similarly, the bootstrap utility class helps the developer make the website more responsive with just one utility class. With the help of these classes, the developer can save the hassle of writing multiple codes for different screen aspect ratios.
Visibility and Invisibility
This section will discuss utility classes that restrict displaying certain blocks based on the screen aspect ratio and classes that hide particular blocks.
CLASSES |
EXTRA SMALL DEVICES (<786 pixels) |
SMALL DEVICES (>= 786 pixels) |
MEDIUM DEVICES (>=992 pixels) |
LARGE DEVICES (>=1200 pixels) |
.visible-xs | Visible | Hidden | Hidden | Hidden |
.visible-sm | Hidden | Visible | Hidden | Hidden |
.visible-md | Hidden | Hidden | Visible | Hidden |
.visible-lg | Hidden | Hidden | Hidden | Visible |
.hidden-xs | Hidden | Visible | Visible | Visible |
.hidden-sm | Visible | Hidden | Visible | Visible |
.hidden-md | Visible | Visible | Hidden | Visible |
.hidden-lg | Visible | Visible | Visible | Hidden |
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>CodingNinjas</title>
<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>
<style media="screen">
body{
padding : 20px;
}
</style>
</head>
<body>
<h1 class="visible-xs bg-danger">This text is shown only on an EXTRA SMALL screen.</h1>
<h1 class="visible-sm bg-info">This text is shown only on a SMALL screen.</h1>
<h1 class="visible-md bg-warning">This text is shown only on a MEDIUM screen.</h1>
<h1 class="visible-lg bg-success">This text is shown only on a LARGE screen.</h1>
</body>
</html>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>CodingNinjas</title>
<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>
<style media="screen">
body{
padding : 20px;
}
</style>
</head>
<body>
<h1 class="hidden-xs bg-danger">This text is hidden on an EXTRA SMALL screen.</h1>
<h1 class="hidden-sm bg-info">This text is hidden on a SMALL screen.</h1>
<h1 class="hidden-md bg-warning">This text is hidden on a MEDIUM screen.</h1>
<h1 class="hidden-lg bg-success">This text is hidden on a LARGE screen.</h1>
</body>
</html>