- Published on
6 Easy Ways To Build A Fixed Height Scrollable Table With Tailwind CSS

- What is Tailwind CSS?
- The description of Fixed Height Scrollable Table ui component
- Why use Tailwind CSS to create a Fixed Height Scrollable Table ui component?
- The preview of Fixed Height Scrollable Table ui component
- The source code of Fixed Height Scrollable Table ui component
- How to create a Fixed Height Scrollable Table with Tailwind CSS?
- Install tailwind css of verion 0.3.0
- All the unility class needed to create a Fixed Height Scrollable Table component
- 12 steps to create a Fixed Height Scrollable Table component with Tailwind CSS
- Conclusion
What is Tailwind CSS?
Tailwind CSS is a utility-first CSS framework that focuses on creating personalized user interfaces quickly. It can gives you all the building blocks you are able to create personalized designs without having to fight to override irritating opinionated styles. Also, Tailwind CSS is a highly configurable, low-level CSS framework.
The description of Fixed Height Scrollable Table ui component
Displaying a table using flexbox allows you to apply fixed heights to certain areas. in this example, the table body has a height of 50vh, or half the viewport. because flexbox styles overwrite many table defaults, we need to reset them using flex properties instead. this example uses tailwind css, but the same techniques can be applied with vanilla css or any other flexbox supporting framework. note how flex styles are being applied to the table head, table body, and table row tags. also, note the fixed widths being applied to each.
Why use Tailwind CSS to create a Fixed Height Scrollable Table ui component?
- It can make the building process of Fixed Height Scrollable Table ui component faster and more easily.
- Enables building complex responsive layouts and components freely.
- Minimum lines of CSS code in Fixed Height Scrollable Table component file.
The preview of Fixed Height Scrollable Table ui component
Free download of the Fixed Height Scrollable Table's source code
The source code of Fixed Height Scrollable Table ui component
<div class="container">
<h1 class="mb-8">
Scrollable Table Fixed Height
</h1>
<table class="text-left w-full">
<thead class="bg-black flex text-white w-full">
<tr class="flex w-full mb-4">
<th class="p-4 w-1/4">One</th>
<th class="p-4 w-1/4">Two</th>
<th class="p-4 w-1/4">Three</th>
<th class="p-4 w-1/4">Four</th>
</tr>
</thead>
<!-- Remove the nasty inline CSS fixed height on production and replace it with a CSS class — this is just for demonstration purposes! -->
<tbody class="bg-grey-light flex flex-col items-center justify-between overflow-y-scroll w-full" style="height: 50vh;">
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
<tr class="flex w-full mb-4">
<td class="p-4 w-1/4">Dogs</td>
<td class="p-4 w-1/4">Cats</td>
<td class="p-4 w-1/4">Birds</td>
<td class="p-4 w-1/4">Fish</td>
</tr>
</tbody>
</table>
</div>
How to create a Fixed Height Scrollable Table with Tailwind CSS?
Install tailwind css of verion 0.3.0
Use the link
html tag to import the stylesheet of Tailwind CSS of the version 0.3.0
<link href=https://unpkg.com/[email protected]/dist/tailwind.min.css rel="stylesheet">
All the unility class needed to create a Fixed Height Scrollable Table component
mb-8
text-left
w-full
bg-black
flex
text-white
mb-4
p-4
w-1/4
bg-grey-light
flex-col
overflow-y-scroll
12 steps to create a Fixed Height Scrollable Table component with Tailwind CSS
Control the margin on bottom side of an element to 2rem using the
mb-8
utilities.Control the text color of an element to left using the
text-left
utilities.Use
w-full
to set an element to a 100% based width.Control the background color of an element to black using the
bg-black
utilities.Use
flex
to create a block-level flex container.Control the text color of an element to white using the
text-white
utilities.Control the margin on bottom side of an element to 1rem using the
mb-4
utilities.Control the padding on all sides of an element to 1rem using the
p-4
utilities.Use
w-1/4
to set an element to a fixed width(1/4).Control the background color of an element to grey-light using the
bg-grey-light
utilities.Use
flex
to create a block-level flex container.Use
overflow-y-scroll
to allow vertical scrolling and always show scrollbars unless always-visible scrollbars are disabled by the operating system.
Conclusion
The above is a step-by-step tutorial on how to use Tailwind CSS to create a Fixed Height Scrollable Table components, learn and follow along to implement your own components.