Introduction

In this article we will create Bootstrap Panels with different styles. Bootstrap panel components are useful when sometimes we want to put content in a box on the webpages.

Panels

A panel in bootstrap is a bordered box with some padding around its content. To create a basic panel,we use .panel class to the <div> element, and content inside the panel has a .panel-body class.

Example 1 : Creating Panel

In this example we will create a basic panel by using .panel class to the <div> element and we will write content in the panel by using .panel-body class to the <div> element. In this example we will use .panel-default class for styling of the panel by writing the following code.
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Bootstrap Part7</title>
  6. <meta name="viewport" content="width=device-width,initial-scale=1">
  7. <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
  8. </head>
  9. <body>
  10. <div class="container">
  11. <h2>Bootstrap Panel</h2>
  12. <div class="panel panel-default">
  13. <div class="panel-body">Demo Panel</div>
  14. </div>
  15. </div>
  16. <script src="js/jquery-2.1.4.min.js"></script>
  17. <script src="js/bootstrap.min.js"></script>
  18. </body>
  19. </html>
Output



Panel Heading

We can add a heading to our panel by using .panel-heading class.

Example 2: Creating Panel with Heading

In this example we will add .panel-heading class for creating Heading of the panel by writing the following code.
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Bootstrap Part7</title>
  6. <meta name="viewport" content="width=device-width,initial-scale=1">
  7. <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
  8. </head>
  9. <body>
  10. <div class="container">
  11. <h2>Bootstrap Panel With Heading</h2>
  12. <div class="panel panel-default">
  13. <div class="panel-heading">Panel Heading</div>
  14. <div class="panel-body">Panel Body:Content Write Here...</div>
  15. </div>
  16. </div>
  17. <script src="js/jquery-2.1.4.min.js"></script>
  18. <script src="js/bootstrap.min.js"></script>
  19. </body>
  20. </html>
Output



Panel Heading With Title

We can use heading elements from <h1> to <h6> with a .panel-title class.

Example 3: Panel Title

In this example we will use .panel-title class for creating Panel Title by writing following code.
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Bootstrap Part7</title>
  6. <meta name="viewport" content="width=device-width,initial-scale=1">
  7. <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
  8. </head>
  9. <body>
  10. <div class="container">
  11. <h2>Bootstrap Panel Heading With Title</h2>
  12. <div class="panel panel-default">
  13. <div class="panel-heading">
  14. <h1 class="panel-title">Panel Title</h1>
  15. </div>
  16. <div class="panel-body">Panel Body:Content Will Be Here...</div>
  17. </div>
  18. </div>
  19. <script src="js/jquery-2.1.4.min.js"></script>
  20. <script src="js/bootstrap.min.js"></script>
  21. </body>
  22. </html>
Output



Panel Footer

We can add a footer to our panels by using the .panel-footer class. In footer we can add text, links, buttons etc.

Example 4: Panel with Footer

In this example we will create footer of the panel by using .panel-footer class by writing the following code.
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Bootstrap Part7</title>
  6. <meta name="viewport" content="width=device-width,initial-scale=1">
  7. <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
  8. </head>
  9. <body>
  10. <div class="container">
  11. <h2>Bootstrap Panel Footer</h2>
  12. <div class="panel panel-default">
  13. <div class="panel-body">Panel Body:Content Will Be Here...</div>
  14. <div class="panel-footer">Panel Footer</div>
  15. </div>
  16. </div>
  17. <script src="js/jquery-2.1.4.min.js"></script>
  18. <script src="js/bootstrap.min.js"></script>
  19. </body>
  20. </html>
Output



Panel Group

We can group many panels together, by wrapping a <div> with class .panel-group around them. The .panel-group class clears the bottom-margin of each panel.

Example 5: Creating Panel Group

In this example we will create Panels and Group it by using .panel-group class by writing the following code.
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Bootstrap Part7</title>
  6. <meta name="viewport" content="width=device-width,initial-scale=1">
  7. <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
  8. </head>
  9. <body>
  10. <div class="container">
  11. <h2>Bootstrap Panel Group</h2>
  12. <!--Panel Group Start-->
  13. <div class="panel-group">
  14. <!--Panel 1 Start-->
  15. <div class="panel panel-default">
  16. <div class="panel-heading">Panel 1 Heading</div>
  17. <div class="panel-body">Panel Content</div>
  18. </div>
  19. <!--Panel 1 End-->
  20. <!--Panel 2 Start-->
  21. <div class="panel panel-default">
  22. <div class="panel-heading">Panel 2 Heading</div>
  23. <div class="panel-body">Panel Content</div>
  24. </div>
  25. <!--Panel 2 End-->
  26. <!--Panel 3 Start-->
  27. <div class="panel panel-default">
  28. <div class="panel-heading">Panel 3 Heading</div>
  29. <div class="panel-body">Panel Content</div>
  30. </div>
  31. <!--Panel 3 End-->
  32. <!--Panel 4 Start-->
  33. <div class="panel panel-default">
  34. <div class="panel-heading">Panel 4 Heading</div>
  35. <div class="panel-body">Panel Content</div>
  36. </div>
  37. <!--Panel 4 End-->
  38. </div>
  39. <!--Panel Group End-->
  40. </div>
  41. <script src="js/jquery-2.1.4.min.js"></script>
  42. <script src="js/bootstrap.min.js"></script>
  43. </body>
  44. </html>
Output



Panels with Contextual Classes

To color the panel for particular context we can use contextual classes as
  • .panel-default
  • .panel-primary
  • .panel-success
  • .panel-info
  • .panel-warning
  • .panel-danger
Example 6: Panels with Contextual Classes

In this example we will create panels with heading and we will use Contextual Classes for making panels more meaningful by writing the following code.
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Bootstrap Part7</title>
  6. <meta name="viewport" content="width=device-width,initial-scale=1">
  7. <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
  8. </head>
  9. <body>
  10. <div class="container">
  11. <h2>Bootstrap Panel Contextual States</h2>
  12. <!--Panel 1 Start-->
  13. <div class="panel panel-default">
  14. <div class="panel-heading">
  15. <h2 class="panel-title">Default Panel</h2>
  16. </div>
  17. <div class="panel-body">Panel Content</div>
  18. </div>
  19. <!--Panel 1 End-->
  20. <!--Panel 2 Start-->
  21. <div class="panel panel-primary">
  22. <div class="panel-heading">
  23. <h2 class="panel-title">Primary Panel</h2>
  24. </div>
  25. <div class="panel-body">Panel Content</div>
  26. </div>
  27. <!--Panel 2 End-->
  28. <!--Panel 3 Start-->
  29. <div class="panel panel-success">
  30. <div class="panel-heading">
  31. <h2 class="panel-title">Success Panel</h2>
  32. </div>
  33. <div class="panel-body">Panel Content</div>
  34. </div>
  35. <!--Panel 3 End-->
  36. <!--Panel 4 Start-->
  37. <div class="panel panel-info">
  38. <div class="panel-heading">
  39. <h2 class="panel-title">Info Panel</h2>
  40. </div>
  41. <div class="panel-body">Panel Content</div>
  42. </div>
  43. <!--Panel 4 End-->
  44. <!--Panel 5 Start-->
  45. <div class="panel panel-warning">
  46. <div class="panel-heading">
  47. <h2 class="panel-title">Warning Panel</h2>
  48. </div>
  49. <div class="panel-body">Panel Content</div>
  50. </div>
  51. <!--Panel 5 End-->
  52. <!--Panel 6 Start-->
  53. <div class="panel panel-danger">
  54. <div class="panel-heading">
  55. <h2 class="panel-title">Danger Panel</h2>
  56. </div>
  57. <div class="panel-body">Panel Content</div>
  58. </div>
  59. <!--Panel 6 End-->
  60. </div>
  61. <script src="js/jquery-2.1.4.min.js"></script>
  62. <script src="js/bootstrap.min.js"></script>
  63. </body>
  64. </html>
Output


In this article we focused on Bootstrap Panels. Then in next articles we will understand all the components of Bootstrap step by step.
Read more articles on Bootstrap: