Type to generate UI components from text


Browse thousands of MUI, Tailwind, React components that are fully customizable and responsive.

Explore Components

Complete Guide to Understanding How Bootstrap Panel Works

Are you looking to make some content stand out on your web page? Using Bootstrap panels lets you customize specific sections on your website.

Panels add a bordered box with some padding around its content. This tutorial will show you how to use panels in your Bootstrap website.

Before we get started, here is a brief introduction to Bootstrap and its role in modern web design.

Introduction to Bootstrap

Bootstrap is a comprehensive framework that aids designers and developers in creating responsive, mobile-first websites. The power of Bootstrap lies in its collection of pre-designed components and grid system.

These elements allow for rapid yet detailed web development, enabling the creation of aesthetically pleasing and functional websites with relative ease.

Speaking of rapid web development, PureCode AI provides a library of over 10k AI-generated templates. These templates can be used to build any aspect of your website.

Explore PureCode AI templates

Understanding Panels in Bootstrap

Panels in Bootstrap play a critical role in content organization and presentation. They are akin to containers that wrap elements such as text, lists, and images, providing a structured and bordered area within web pages.

The primary function of a Bootstrap panel is to offer a visually distinct section that separates content for better readability.

Note: Bootstrap panels were available in version 3 and below. However, they’ve been replaced by the Bootstrap Card component. To learn more, see our Bootstrap Card tutorial for a complete walkthrough.

The Role of Panels in Modern Web Design

Adding panels to a web page is more than a stylistic choice; it’s a strategic approach to enhancing user experience and website functionality. Below are the key roles this component plays in web design.

  1. Aesthetic Structure: Panels give web pages a sense of order and clarity. They break down content into manageable sections, making it easier for users to process information.

  2. Enhanced User Experience: A well-organized website is a user-friendly website. Panels contribute to a logical layout, guiding users through content intuitively.

  3. Focus on Important Content: By framing key pieces of information within panels, designers can direct user attention to specific areas of a page. This is useful for highlighting calls to action, important updates, or featured content.

  4. Responsiveness: Panels help create responsive designs that adapt seamlessly across different devices. This flexibility ensures a consistent and accessible user experience, regardless of the device used.

Definition of a Panel in Bootstrap

In Bootstrap, a panel is a bordered box with some padding around its content. It’s a lightweight, flexible component designed to house content neat and orderly.

Panels often contain and highlight certain information or interface elements, making them distinct from the rest of the page’s content.

Basic Structure of a Bootstrap Panel

A typical Bootstrap panel comprises three main parts:

  1. Panel Heading: This is typically a title or label for the panel’s content. A header element often includes text or other elements like buttons.

  2. Panel Body: This is the main content area of the panel. It can include text, lists, images, or any other HTML content.

  3. Panel Footer: This is an optional section used for additional information or action elements related to the panel’s content.

Here’s a basic example of a Bootstrap panel:

<div class="panel panel-default">
  <!-- Panel Heading -->
  <div class="panel-heading">Panel Title</div>

  <!-- Panel Body -->
  <div class="panel-body">
    Panel content goes here. This can be text, images, forms, etc.

  <!-- Panel Footer (optional) -->
  <div class="panel-footer">Panel footer</div>

In this example, we have a div with a class of panel and panel-default, which defines the basic panel. Inside this div, we have three child elements:

  1. panel-heading for the title,

  2. panel-body for the main content,

  3. panel-footer for any additional information.

Using Bootstrap Panels

Now you have a basic understanding of what Bootstrap is and how panels work. Let’s discuss how you can include it in your web application.

Including Bootstrap in Your Project

To use Bootstrap, you need to include its CSS and JavaScript files in your project. There are two primary ways to do this:

1. Using a CDN (Content Delivery Network): This is the easiest way to include Bootstrap. Simply add the following lines in the <head>section of your HTML file:

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<!-- Popper JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

2. Downloading Bootstrap: Alternatively, you can download Bootstrap from getbootstrap.com and include the files directly in your project. This method is useful if you want to work offline or have more control over the Bootstrap files.

Note: To use panels, you’ll need to install and include Bootstrap version 3 to your project.

Basic HTML Structure for a Bootstrap Panel

In Bootstrap 3, panels were used to create a bordered box with some padding around it. However, it’s important to note that as of Bootstrap 4, panels have been replaced with cards. Here’s how you can create a basic Bootstrap 3 panel:

<div class="panel panel-default">
    <div class="panel-heading">Panel Heading</div>
    <div class="panel-body">Panel Content</div>
    <div class="panel-footer">Panel Footer</div>

And for Bootstrap 4 and later, using cards:

<div class="card">
    <div class="card-header">Card Header</div>
    <div class="card-body">
        <h5 class="card-title">Card Title</h5>
        <p class="card-text">Some content inside the card.</p>
    <div class="card-footer">Card Footer</div>

In both examples, the structure consists of a container (panel or card) with optional heading, body, and footer sections. These sections are denoted with respective classes like panel-heading/card-header, panel-body/card-body, and panel-footer/card-footer.

For this tutorial, we’ll focus more on using Panels. If you’d like to learn about the more recent Card component, be sure to check out our tutorial.

Customizing Panels

Let’s dive into customizing Bootstrap panels, focusing on changing their colors and adding custom styles. Remember, these examples will primarily reference Bootstrap 3, as panels were a distinct component in this version. In Bootstrap 4 and later, cards replace panels, but similar principles apply.

Changing Panel Colors Using Bootstrap Context Classes

Bootstrap comes with a set of contextual classes designed to give meaning through color. These are typically used for components like panels, alerts, and buttons to indicate the nature of the content (like success, info, warning, danger, etc.).

Here’s how you can use these context classes with panels:

  1. Default Panel: This is the basic panel style.

    <div class="panel panel-default">...</div>
  2. Primary Panel: Use this for primary information.

    <div class="panel panel-primary">...</div>
  3. Success Panel: Ideal for positive messages, like successful actions.

    <div class="panel panel-success">...</div>
  4. Info Panel: Good for informational messages.

    <div class="panel panel-info">...</div>
  5. Warning Panel: Use when warning the user.

    <div class="panel panel-warning">...</div>
  6. Danger Panel: Perfect for error messages or critical issues.

    <div class="panel panel-danger">...</div>

Each class will apply a different color scheme to your panel, aligning with the intended context.

Adding Custom Styles to Panels

You can add your own CSS to further customize panels beyond the default Bootstrap styles. Here’s how to do this:

Start by creating a custom CSS file and including it in your HTML after the Bootstrap CSS file. This ensures your custom styles override the default Bootstrap styles.

You’ll need to add a custom class to style a specific panel. For this example, we’ll name ours my-custom-panel, but you can use any name you’d like:

<div class="panel panel-default my-custom-panel">...</div>

After specifying the CSS class name, you’ll need to add the styles for the class in your CSS file. Here is an example.

.my-custom-panel {
    background-color: #f2f2f2;
    border-color: #333;
    // More custom styles

If you’d like, you can customize specific parts of the panel, like the panel header, body, or footer. Here is an example.

.my-custom-panel > .panel-heading {
    background-color: #333;
    color: white;
    // Other styles

.my-custom-panel > .panel-body {
    padding: 20px;
    // Other styles

.my-custom-panel > .panel-footer {
    background-color: #e7e7e7;
    // Other styles

In the code above, we’ve added custom styles for each of the panel components. Remember, when customizing styles, it’s essential to maintain a balance between uniqueness and consistency with the overall design of your website.

Advanced Features

Let’s explore some of the advanced features of Bootstrap, specifically focusing on making panels collapsible and integrating panels with other Bootstrap components like grids and tables.

Collapsible Panels Using Bootstrap JavaScript

One of the dynamic features you can implement with Bootstrap is creating collapsible panels. The user can expand or collapse these panels, making it convenient to manage large amounts of content in a limited space.

This is particularly useful for FAQs, product descriptions, or content that benefits from a clean, organized layout. Here’s how to create a collapsible panel:

  1. Basic Structure: You need a panel (or card in Bootstrap 4) and some additional Bootstrap components like buttons to trigger the collapse action.

  2. Using data- Attributes: Bootstrap utilizes data- attributes for handling collapse functionality.

Here’s an example using Bootstrap 3 syntax:

<div class="panel panel-default">
    <div class="panel-heading">
        <h4 class="panel-title">
            <a data-toggle="collapse" href="#collapsePanel">
                Click to toggle panel
    <div id="collapsePanel" class="panel-collapse collapse">
        <div class="panel-body">
            Content of the collapsible panel.

In the code above:

  • The data-toggle=”collapse” attribute in the anchor (<a>) tag indicates that it will be used to toggle a collapsible element.

  • The href=”#collapsePanel” attribute links this anchor tag to the collapsible content by referencing its id.

  • The panel-collapse and collapse classes define the collapsible part of the panel. The collapse class makes it collapsed by default.

  • The id=”collapsePanel” is the ID of the div that will be shown/hidden when the anchor tag is clicked.

Including Bootstrap JavaScript

For the collapsible functionality to work, you’ll need to include Bootstrap’s JavaScript file and jQuery (since Bootstrap 3 relies on it). Add these lines, typically at the bottom of your HTML file, before the closing </body> tag:

<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>

Customizing the Collapsible Behavior

If you want the panel to be expanded by default, remove the collapse class from the panel-collapse div. To have multiple collapsible panels that work independently, ensure each panel has a unique ID and that the href attribute of each corresponding toggle link matches its respective ID.

Integrating Panels with Other Bootstrap Components

Bootstrap panels can seamlessly integrate with other components like grids and tables to create more complex and functional layouts.

1. Panels with Grid System:

Bootstrap’s grid system allows you to place panels within columns, which can be very useful for creating structured layouts.

<div class="row">
    <div class="col-md-6">
        <div class="panel panel-default">
            <!-- Panel content -->
    <div class="col-md-6">
        <div class="panel panel-default">
            <!-- Panel content -->

Here, two panels are placed side by side using Bootstrap’s grid columns (col-md-6). Please see our Bootstrap Grid tutorial to learn more about the grid system.

2. Panels with Tables:

You can also place tables within panels to group the table content and provide a clearer structure.

<div class="panel panel-default">
    <div class="panel-heading">Employee Details</div>
    <div class="panel-body">
        <table class="table">
                    <td>John Doe</td>
                    <td>Software Engineer</td>
                    <td>Jane Smith</td>
                    <td>Project Manager</td>
                    <td>Emily Johnson</td>
                    <td>Graphic Designer</td>
                <!-- Add more rows as needed -->

In the code above,

  • The panel-heading contains the title “Employee Details”.

  • Inside the panel-body, a Bootstrap table (table class) is created.

  • The <thead> section contains headers for the table columns: ID, Name, Position, and Department.

  • The <tbody> section contains rows of dummy data representing employees.

In this example, the table is nested inside a panel, giving it a neat, bordered look while separating it from the rest of the page content.

Bootstrap Well vs. Panel

A Bootstrap well is designed to visually make a section of content stand out by giving it an inset effect. It’s like creating a shallow pit where the content sits on your webpage. This is useful for highlighting a part of the page without adding too much structure or complexity.

Panels in Bootstrap are more structured than wells. They enclose content with a clear boundary and are ideal for organizing complex content sections. Panels come with optional headers and footers, making them suitable for displaying grouped information, such as in dashboards, organized lists, etc.

Panels vs Wells in Bootstrap

AppearancePanels have a bordered frame with optional header and footer sections.Wells provides a simple, rounded-corner box with a light padding around the content and a slightly inset background
UsageA panel is created by using a combination of .panel, .panel-heading, .panel-body, and .panel-footer classes.To use a well, you simply wrap your content in a div with a class of .well.
When to use?Use panels when your content needs a more defined and organized presentation, like in a user interface with multiple data sections.Use wells when you want to draw attention to a piece of content without the need for a structured container.

Best Practices

It is crucial to follow best practices when using Bootstrap panels (or their successor, cards, in Bootstrap 4 and later). This ensures that your website is responsive, accessible, and performs well. Here are some key considerations and tips:

Responsive Design with Panels

Responsive design practice ensures your content adjusts and looks good across multiple devices and screen sizes. Bootstrap is responsive by default. However, we recommend building on the framework’s responsive nature to ensure your content looks good. Here are some tips to consider when building out your website.

  1. Use Bootstrap’s Grid System: Place your panels within Bootstrap’s grid layout to ensure they are responsive. The grid system automatically allows your panels to adjust and resize based on the screen size.

  2. Avoid Fixed Widths: Use relative units like percentages rather than fixed units like pixels. This ensures that your panels scale with the screen size.

  3. Test on Multiple Devices: Regularly test your layout on various devices to ensure panels look good on all screen sizes.

Accessibility Considerations

  1. Use Semantic HTML: Ensure that the structure of your panels uses appropriate HTML elements. For example, use <div> for containers, <h1> to <h6> for headings, <p> for paragraphs, etc. This improves screen reader interpretation.

  2. Contrast and Color: Make sure the text in your panels has a high contrast ratio for better readability, especially for users with visual impairments.

  3. Keyboard Navigation: Ensure all interactive elements in your panels are accessible via keyboard. For example, if your panels are collapsible, they should be operable using keyboard controls.

  4. ARIA Attributes: Use ARIA (Accessible Rich Internet Applications) attributes where necessary to provide additional context to assistive technologies.

Frequently Asked Questions

Below, we’ve answered some of the top questions about using Bootstrap Panels.

What is a Bootstrap panel?

A Bootstrap panel is a bordered box with some padding around it. In Bootstrap 3, it was a popular component for placing content because it provided a clear, visible boundary around text, images, or other elements.

How do you add a panel in HTML?

To add a panel in HTML using Bootstrap 3, you would structure it as follows:

<div class="panel panel-default">
  <div class="panel-heading">Panel Heading</div>
  <div class="panel-body">
    Some default panel content here.
  <div class="panel-footer">Panel Footer</div>

This creates a basic panel with a heading, body, and footer. The panel-default class applies the standard styling. To change the look and feel, you can replace panel-default with other classes like panel-primary, panel-success, etc.

Does Bootstrap 5 have panels?

No, Bootstrap 5 does not include panels as they were in Bootstrap 3. Panels were phased out in Bootstrap 4 and replaced by cards. A Bootstrap card serves a similar purpose but is more versatile and modern. Cards can be used to display a wide variety of content and are more flexible in terms of layout and customization.

Final Thoughts on Bootstrap Panel

Bootstrap Panels are a reliable way to highlight a particular content on your web page. However, it only works if you’re using Bootstrap 3. If you’re using the latest version of Bootstrap, consider using cards instead.

In this tutorial, we explained all there is to know about using Panels in Bootstrap. We also covered customization options like adding tables to your panel and updating the panel’s background color using Bootstrap’s contextual classes.

This should give you a good understanding of how they work.

Building with Bootstrap speeds up development time. However, you can take it further and use some of PureCode AI’s ready-made templates. PureCode provides over 10k AI-generated templates to cater to any component you intend to build on your app.

Checkout PureCode AI Templates

Further Reading:

If you enjoyed this post, check out others from our blog to help you become a better developer.

David Ozokoye

David Ozokoye

Software Engineer and Technical Writer