Bootstrap table with a fixed header

Published: 9.5.2019 | Last update: 10.6.2022

With the help of a couple of CSS classes, you can easily create fixed headers for your responsive tables with Bootstrap 4 or 5.

In this short tutorial, I will show you how to create such sticky headers for your table. You can scroll the table contents and the header will remain in its place.

The table with its sticky header will be responsive and nicely displayed on smaller viewports. The code is easy to implement and customize to meet your specific needs.

Alright, let's do it!

Step-by-step Instructions

  • don't forget to wrap your fixed table header row in a thead wrapper
  • we limit tbody height to 300px (add your value) and set overflow-y to scroll. All this is done in CSS.
  • then to make everything work, we have to set the table's rows and cells to display: block and float: left

When to use a table with a fixed header in web design?

When you need to display data in tabular form, it is better if you can do it in a table with a fixed header. This is because it makes the content easier to read and understand.

A table with a fixed header could be used to display data usually found in an Excel sheet or database. The information can be easily arranged into columns and rows. It is also easy to identify the main content of each column.

If you liked this snippet, you might also enjoy exploring Bootstrap vertical menu or Bootstrap Multiselect Dropdown .

Please note that the interactive editor on this page should be viewed on your laptop or desktop for the best results.

See my free Bootstrap themes Edit this snippet

How to use the snippet

There are two ways to use the snippet:

  • a] Copy it into your project. This means:
    1. Copy content of the HTML, CSS, JavaScript tabs into your project
    2. Make sure that you have jQuery 3 and Bootstrap 4's CSS and JS included in your project too.
    3. That should be it, and you should be good to go.
  • b] Use the "Edit in JSFiddle" link in the top right and play with it in the JSFiddle. After adjusting what you need, you can use the same steps as in a] to develop it locally.
Share on Facebook Share on Twitter Share on LinkedIn