Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

How to Create and Style Tables in Bootstrap 5

Create accessible Bootstrap 5 tables, then add striped or hoverable rows, borders, compact spacing, contextual states, dark headers, and responsive scrolling.

Table of Contents

To style an HTML table with Bootstrap 5, add the table class to the <table> element. You can then combine it with modifier classes such as table-striped, table-hover, table-bordered, table-sm, or table-dark. For a wide table, place it inside a table-responsive wrapper so it can scroll horizontally on a small screen.

Bootstrap improves the presentation of a table, but the underlying HTML still matters. Use tables for rows and columns of related data, not for page layout. If you need a refresher on markup, see the guide to modern HTML5 structure. You can also compare Bootstrap with other options in this overview of popular CSS frameworks.

Create a basic Bootstrap 5 table

A useful table normally has a <caption>, a header group in <thead>, and data rows in <tbody>. Column headers use <th scope="col">, while a header that identifies a row uses <th scope="row">. These elements give the data a meaningful structure for assistive technology as well as visual users.

<table class="table">
  <caption>Team members</caption>
  <thead>
    <tr>
      <th scope="col">#</th>
      <th scope="col">First name</th>
      <th scope="col">Last name</th>
      <th scope="col">Role</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">1</th>
      <td>Ava</td>
      <td>Nguyen</td>
      <td>Designer</td>
    </tr>
    <tr>
      <th scope="row">2</th>
      <td>Noah</td>
      <td>Tran</td>
      <td>Developer</td>
    </tr>
  </tbody>
</table>
Team members
#First nameLast nameRole
1AvaNguyenDesigner
2NoahTranDeveloper

Basic table styled with the Bootstrap table class

Bootstrap's table styling is opt-in. A plain <table> does not receive these styles until you add class="table". This also prevents the styles from automatically cascading into a nested table.

Choose the right table modifier

Start with table, then add only the modifiers the design needs. The most commonly used options are:

ClassEffect
table-stripedAdds alternating shading to rows in the table body.
table-striped-columnsAdds alternating shading to columns.
table-hoverHighlights body rows when the pointer is over them.
table-borderedAdds a border around every cell.
table-borderlessRemoves table and cell borders.
table-smReduces cell padding for a more compact table.
table-darkApplies Bootstrap's dark table variant.

Striped rows

Add table-striped when alternating row shading will help readers follow a long row across several columns:

<table class="table table-striped">
  ...
</table>

Bootstrap table with striped rows

Borders and hover highlighting

Use table-bordered when clear cell boundaries are important. If the table is already visually dense, a border on every cell may add clutter, so compare it with Bootstrap's default horizontal dividers.

<table class="table table-bordered">
  ...
</table>

Bootstrap table with borders around each cell

The table-hover class adds a visual hover state to rows inside <tbody>. It can help someone track the row under the pointer, but it should not be the only way to communicate a selected or important state.

<table class="table table-hover">
  ...
</table>

Bootstrap table with a hovered row

Dark and combined styles

Add table-dark to the table for a dark variant:

<table class="table table-dark">
  ...
</table>

Dark Bootstrap table

Modifiers can be combined. For example, the following table uses the dark variant and highlights body rows on hover:

<table class="table table-dark table-hover">
  ...
</table>

Dark Bootstrap table with a hover effect

You can similarly combine table-dark with table-striped. Check the contrast after combining classes, especially if you also add custom colors.

Borderless tables

Use table-borderless when grouping, spacing, and alignment make the row and column relationships clear without rules:

<table class="table table-borderless">
  ...
</table>

Borderless Bootstrap table

Apply contextual table colors

Bootstrap provides contextual variants that can be applied to a whole table, an individual row, or a cell. They are named table-primary, table-secondary, table-success, table-danger, table-warning, table-info, table-light, and table-dark. The table-active class identifies an active row or cell.

ExampleTypical interface meaning
table-primaryPrimary or emphasized item
table-successSuccessful or positive state
table-dangerError or dangerous state
table-warningState that needs attention
table-infoInformational state
table-activeCurrent or active item

Contextual color variants in a Bootstrap table

Do not rely on color alone. Add a text label, icon with an accessible name, or another cue so the state is understandable to people who cannot distinguish the colors.

Style the table header

A contextual class can be applied to <thead>. For a standard dark or light header in Bootstrap 5, use table-dark or table-light. The older thead-dark and thead-light classes belong to Bootstrap 4 and should not be used in Bootstrap 5 markup.

<table class="table">
  <thead class="table-dark">
    <tr>
      <th scope="col">Product</th>
      <th scope="col">Status</th>
    </tr>
  </thead>
  ...
</table>

Bootstrap tables with contextual header colors

Make a compact table

The table-sm modifier reduces the cell padding. It is useful for data-heavy admin screens, but the denser layout can make scanning and tapping harder. Use it when compactness matters, not as a default for every table.

<table class="table table-bordered table-sm">
  ...
</table>

Compact Bootstrap table created with table-sm

Make a Bootstrap table responsive

A wide table can overflow a phone screen. Bootstrap's responsive table helper solves this by putting horizontal scrolling on a wrapper. The class belongs on a <div> around the table, not on the table itself:

<div class="table-responsive">
  <table class="table table-bordered">
    ...
  </table>
</div>

Wide Bootstrap table scrolling inside a responsive wrapper

Use table-responsive for scrolling at every viewport size. Breakpoint-specific variants scroll only below the named breakpoint:

Wrapper classResponsive behavior
table-responsive-smScrolls below 576px
table-responsive-mdScrolls below 768px
table-responsive-lgScrolls below 992px
table-responsive-xlScrolls below 1200px
table-responsive-xxlScrolls below 1400px

A responsive wrapper prevents the whole page from widening, but it does not simplify the data. On very narrow screens, consider whether some columns can be omitted, shortened, or moved into a detail view.

Practical table checklist

  • Use a table only for genuinely tabular information.
  • Add a concise <caption> when the table's purpose is not already obvious.
  • Mark column and row headers with <th> and the correct scope.
  • Start with table, then add only the modifiers that improve comprehension.
  • Use labels or icons as well as contextual color.
  • Wrap wide tables in a responsive container and test keyboard as well as touch scrolling.

You can edit and test these examples in one of the HTML editors for Windows. For the complete set of table options, consult the official Bootstrap tables documentation.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.