Bootstrap Tutorial menu

Bootstrap Tables and Images

With one or two classes, Bootstrap turns plain tables and images into clean, responsive ones.

A Basic Table

Add the class table to any <table>. Bootstrap adds padding, lines between rows and a neat header.

Example

html
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>

<div class="container mt-4">
  <table class="table">
    <thead>
      <tr><th>#</th><th>Student</th><th>Course</th><th>Marks</th></tr>
    </thead>
    <tbody>
      <tr><td>1</td><td>Ayesha Khan</td><td>Web Development</td><td>91</td></tr>
      <tr><td>2</td><td>Ali Raza</td><td>Graphic Design</td><td>84</td></tr>
      <tr><td>3</td><td>Sana Iqbal</td><td>Python</td><td>88</td></tr>
    </tbody>
  </table>
</div>

</body>
</html>
Try it Yourself »

Table Styles

Add these classes next to table:

ClassEffect
table-stripedEvery other row is shaded
table-borderedBorders on all cells
table-borderlessNo borders
table-hoverRows highlight when the mouse is over them
table-smSmaller padding, more compact
table-darkDark table with light text

Coloured Rows and a Responsive Wrapper

You can colour a single row or cell with table-success, table-danger, table-warning and so on. Wrap wide tables in table-responsive so they scroll sideways on small phones instead of breaking the page.

Example

html
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>

<div class="container mt-4">
  <div class="table-responsive">
    <table class="table table-striped table-hover table-bordered align-middle">
      <thead class="table-dark">
        <tr><th>Invoice</th><th>Customer</th><th>Date</th><th>Amount</th><th>Status</th></tr>
      </thead>
      <tbody>
        <tr><td>INV-101</td><td>Hamza Traders</td><td>02-10-2026</td><td>Rs 12,500</td><td>Paid</td></tr>
        <tr class="table-warning"><td>INV-102</td><td>Karachi Prints</td><td>05-10-2026</td><td>Rs 8,200</td><td>Due soon</td></tr>
        <tr class="table-danger"><td>INV-103</td><td>Star Mobiles</td><td>20-09-2026</td><td>Rs 4,750</td><td>Late</td></tr>
      </tbody>
    </table>
  </div>
</div>

</body>
</html>
Try it Yourself »

align-middle centres the cell content vertically. table-dark on <thead> makes only the header dark.

Use colour together with words (like "Paid" or "Late"). Some people cannot tell red and green apart, so colour alone is not enough.

Images

ClassEffect
img-fluidThe image never gets wider than its parent (responsive)
roundedSlightly rounded corners
rounded-circleRound image (use a square picture)
img-thumbnailA white border with a light frame
mx-auto d-blockCentres a block image

Example

html
<img src="shop-front.jpg" class="img-fluid rounded" alt="Front of Ali's shop on Tariq Road">
<img src="ayesha.jpg" class="rounded-circle" width="120" height="120" alt="Ayesha, our teacher">
<img src="certificate.jpg" class="img-thumbnail" width="200" alt="Course certificate">

img-fluid is the most important one. Without it, a large photo can be wider than a phone screen and make the whole page scroll sideways.

Figures with Captions

Example

html
<figure class="figure">
  <img src="lab.jpg" class="figure-img img-fluid rounded" alt="Computer lab">
  <figcaption class="figure-caption">Our computer lab in Orangi Town.</figcaption>
</figure>

Always write a helpful alt text. It is read by screen readers and shown if the image fails to load.

Exercise

Exercise

Which class makes table rows change colour when the mouse moves over them?

Learn Bootstrap with a teacher

Join the Web Development course at Workownix, online or in Orangi Town, Karachi, and get a certificate.

See the course Ask on WhatsApp