How to Create a Card with Tabs & Content in Bootstrap 5 ?
Last Updated :
30 Jul, 2024
We will create a Card with Tabs and content in Bootstrap 5. Bootstrap 5 Cards refers to a user interface where related information is organized into individual cards that can be interacted with and rearranged for easy viewing and access. The individual cards are known as tabs. This approach is commonly used in mobile app design and website design for a visually appealing and organized way of presenting information.
The card is a component provided by Bootstrap 5 which provides a flexible and extensible content container with multiple variants and options. It includes options for headers and footers. Cards support a wide variety of content, including images, text, list groups, links, and more.
Preview

These are the following appraoches:
Approach 1: Using Bootstrap Card Component
These are the following classes we have used in the code to make the card with tabs:
- card: The card class as a parent to create a basic card.
- card-header: The card-header provides a header to the card
- card-body: The basic building block of a card is the card-body.
- nav: It creates a navigation list.
- nav-tabs: This class styles the navigation list to appear as tabs.
- nav-link: This style each individual tab link.
- active: The active class allows you to move quickly and displays the part of the page you are currently in.
- tab-pane: It contains the content associated with each tab.
Example: The following code demonstrates the card with three different tabs with some contents using Bootstrap 5 libraries and it is responsive.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<title>Bootstrap Tabs in Card</title>
<!-- Bootstrap CSS -->
<link href=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet">
<script src=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js">
</script>
<style>
/* Override Bootstrap's link active state styles */
.nav-link {
color: #fff !important;
}
.nav-link.active{
color: rgb(42, 165, 73) !important;
background-color: aliceblue !important;
}
</style>
</head>
<body>
<div class="container text-center">
<div class="mt-1">
<h2 class="text-success">
GeeksforGeeks
</h2>
<h3>
Card with Tabs
and content in Bootstrap 5 ?
</h3>
</div>
<div class="row justify-content-center mt-2">
<div class="col-md-6">
<div class="card">
<div class="card-header bg-success text-white">
<ul class="nav nav-tabs card-header-tabs" id="myTab"
role="tablist">
<li class="nav-item">
<a class="nav-link active" id="tab1-tab"
data-bs-toggle="tab"
href="#tab1" role="tab"
aria-controls="tab1" aria-selected="true">
Read
</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" id="tab2-tab"
data-bs-toggle="tab" href="#tab2" role="tab"
aria-controls="tab2" aria-selected="false">
Practice
</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" id="tab3-tab"
data-bs-toggle="tab" href="#tab3" role="tab"
aria-controls="tab3" aria-selected="false">
Learn
</a>
</li>
</ul>
</div>
<div class="card-body">
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="tab1"
role="tabpanel" aria-labelledby="tab1-tab">
<p>
<strong class="text-success">
Company Profile and Brand
</strong><br>
GeeksforGeeks is a leading platform that provides
computer science resources and coding challenges
for programmers and technology enthusiasts,
along with interview and exam preparations for
upcoming aspirants. With a strong emphasis on
enhancing coding skills and knowledge, it has
become a trusted destination for over 12 million
plus registered users worldwide.
<br/>
Our exceptional mentors hailing from top colleges
& organizations have the ability
<br/>
Our brand is built on the pillars of expertise,
accessibility, and community. We strive to empower
individuals to enhance their programming skills,
to bridge the gap between academia and industry,
and provide a supportive community to the learners.
</p>
<a href=
"https://www.geeksforgeeks.org/" class="text-success">
Visit GeeksforGeeks
</a> <!-- Example link -->
</div>
<div class="tab-pane fade" id="tab2" role="tabpanel"
aria-labelledby="tab2-tab">
<p>This is the content of Tab 2.</p>
</div>
<div class="tab-pane fade" id="tab3" role="tabpanel"
aria-labelledby="tab3-tab">
<p>This is the content of Tab 3.</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Output:
Approach 2: Using nav-tabs
These are the following classes we have used in the code to make the card with tabs:
- container: This class is used to create a responsive fixed-width container to hold the content. It helps to keep the content centered and consistent across different screen sizes.
- nav: It creates a navigation list.
- nav-tabs: This class styles the navigation list to appear as tabs.
nav-link.active: This class is used to style the active tab link. - tab-content : This class is used to contain the content for the tabs.
- tab-pane fade: This class is applied to each tab content div to create a fade effect when switching between tabs.
- show: This class is used to make the content visible.
- active: This class indicates that the content is the active tab.
Example: This example shows the implementation of the above-explained all classes.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<title>Bootstrap Tabs Example</title>
<!-- Bootstrap CSS -->
<link href=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet">
<!-- Bootstrap Bundle JS -->
<script src=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js">
</script>
<style>
/* Override Bootstrap's link active state styles */
.nav-link {
color: #fff !important;
}
.nav-link.active{
color: rgb(42, 165, 73) !important;
background-color: aliceblue !important;
}
</style>
</head>
<body>
<div class="container mt-5">
<h2 class="text-center text-success">
GeeksforGeeks Navigation Tabs Example
</h2>
<ul class="nav nav-tabs justify-content-center bg-success"
id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="home-tab"
data-bs-toggle="tab"
href="#home" role="tab" aria-controls="home"
aria-selected="true">
Home
</a>
</li>
<li class="nav-item">
<a class="nav-link" id="profile-tab"
data-bs-toggle="tab"
href="#profile" role="tab"
aria-controls="profile"
aria-selected="false">
About Us
</a>
</li>
<li class="nav-item">
<a class="nav-link" id="contact-tab"
data-bs-toggle="tab"
href="#contact" role="tab"
aria-controls="contact"
aria-selected="false">
Contact Us
</a>
</li>
</ul>
<div class="tab-content mt-3" id="myTabContent">
<div class="tab-pane fade show active" id="home"
role="tabpanel" aria-labelledby="home-tab">
<h3 class="text-center text-success">Home Content</h3>
<strong class="text-success">
Company Profile and Brand
</strong><br>
GeeksforGeeks is a leading platform that provides
computer science resources and coding challenges
for programmers and technology enthusiasts,
along with interview and exam preparations for
upcoming aspirants. With a strong emphasis on
enhancing coding skills and knowledge, it has
become a trusted destination for over 12 million
plus registered users worldwide.
<br/>
Our exceptional mentors hailing from top colleges
& organizations have the ability
<br/>
Our brand is built on the pillars of expertise,
accessibility, and community. We strive to empower
individuals to enhance their programming skills,
to bridge the gap between academia and industry,
and provide a supportive community to the learners.
</p>
<a href=
"https://www.geeksforgeeks.org/" class="text-success">
Visit GeeksforGeeks
</a>
</div>
<div class="tab-pane fade" id="profile" role="tabpanel"
aria-labelledby="profile-tab">
<h3 class="text-center text-success">
Aboutus Content</h3>
<p>This is the content of the Aboutus tab.</p>
</div>
<div class="tab-pane fade" id="contact" role="tabpanel"
aria-labelledby="contact-tab">
<h3 class="text-center text-success">
Contactus Content</h3>
<p>This is the content of the Contactus tab.</p>
</div>
</div>
</div>
</body>
</html>
Output:
Similar Reads
How to Create Cards in Bootstrap ? Bootstrap cards, use the .card class. Customize content with headings, paragraphs, images, and buttons. Utilize contextual background colors and additional classes for styling and alignment. Cards offer flexible content containers with options for headers, footers, and powerful display settings.In s
3 min read
How to Create Responsive Card with a Video Background in Bootstrap? Cards are very useful things in web development. Cards can hold various types of content, such as text, images, and links, making them perfect for displaying information in a structured format. And the background video can enhance the style of the web page. In this tutorial, we will focus on how to
2 min read
How to Create Dynamic Tabs in Bootstrap ? Bootstrap's dynamic tabs empower web developers by enabling on-demand tab creation. This feature enhances user experience by facilitating dynamic content presentation within a tabbed interface. Admins can effortlessly generate tabs as needed, enriching site interactivity. Tabs in Bootstrap are navig
3 min read
How to create a FAQ Section in Bootstrap ? An FAQ(Frequently Asked Questions) section serves as a valuable resource for users, providing them with the information they need in a convenient and accessible manner while also benefiting the organization by reducing support overhead and enhancing user satisfaction.Table of Content Using Accordion
4 min read
How to Create a Card in Material UI ? To create a card in Material UI, you can use the 'Card' component along with other components like 'CardHeader', 'CardContent', and 'CardActions' to structure content. Customize it with styles and props for a sleek, responsive design that fits your application seamlessly. Installationnpm install @mu
1 min read