How to use hover in bootstrap 5?
Hi Friends 👋,
Welcome To aGuideHub! ❤️
Today, I am going to show you. How to use hover in bootstrap 5 using css with code example.
Here, we will be using the .thumbnail
class to create hover in Bootstrap.
Table of contents
Framework and cdn link setup
Included JS 5 bootstrap
Define its class name
This article will guide you to adding hover in Bootstrap with example.
Step 1: Framework and cdn link setup
First of all, load the Bootstrap 5 framework CSS into the head tag of your webpage.
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
Step 2: Included JS bootstrap
Now, load the Bootstrap JavaScript file before closing the body tag and done.
<!-- Option 1: Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
Step 3: Define its class name
After that, create the hover with a class name .thumbnail
.
<div class="regionPage">
<section class="thumbs">
<h3>Hover effect bootstrap - 5</h3>
<div class="row">
<div class="col-lg-2 col-md-3 col-sm-4 col-xs-6">
<a class="thumbnail" title="Afghanistan" href="../asia/afghanistan.php"><img src="images/royalty.jpg" alt="City"></a>
</div>
</div>
</section>
</div>
Example.
Let’s look at the following example to understand how it basically works:
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<title>Bootstrap</title>
<style>
.thumbnail:hover {
background-color: red;
opacity: 0.5;
}
</style>
</head>
<body>
<div class="regionPage">
<section class="thumbs">
<h3>Hover effect bootstrap - 5</h3>
<div class="row">
<div class="col-lg-2 col-md-3 col-sm-4 col-xs-6">
<a class="thumbnail" title="Afghanistan" href="../asia/afghanistan.php"><img src="images/royalty.jpg" alt="City"></a>
</div>
</div>
</section>
</div>
<!-- Option 1: Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
</body>
</html>
Check the output of the above code example.

All the best 👍