- Published on
6 Ideas To Help You Build A Table With Tailwind CSS Like A Pro

- What is Tailwind CSS?
- The description of Table ui component
- Why use Tailwind CSS to make a Table ui component?
- The preview of Table ui component
- The source code of Table ui component
- How to make a Table with Tailwind CSS?
- Install tailwind css of verion 0.3.0
- All the unility class needed to make a Table component
- 23 steps to make a 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 Table ui component
A table with actions. originally created with the open sans font and fontawesome icons
Why use Tailwind CSS to make a Table ui component?
- It can make the building process of Table ui component faster and more easily.
- Enables building complex responsive layouts and components freely.
- Minimum lines of CSS code in Table component file.
The preview of Table ui component
Free download of the Table's source code
The source code of Table ui component
<div class="w-2/3 mx-auto">
<div class="bg-white shadow-md rounded my-6">
<table class="text-left w-full border-collapse"> <!--Border collapse doesn't work on this site yet but it's available in newer tailwind versions -->
<thead>
<tr>
<th class="py-4 px-6 bg-grey-lightest font-bold uppercase text-sm text-grey-dark border-b border-grey-light">City</th>
<th class="py-4 px-6 bg-grey-lightest font-bold uppercase text-sm text-grey-dark border-b border-grey-light">Actions</th>
</tr>
</thead>
<tbody>
<tr class="hover:bg-grey-lighter">
<td class="py-4 px-6 border-b border-grey-light">New York</td>
<td class="py-4 px-6 border-b border-grey-light">
<a href="#" class="text-grey-lighter font-bold py-1 px-3 rounded text-xs bg-green hover:bg-green-dark">Edit</a>
<a href="#" class="text-grey-lighter font-bold py-1 px-3 rounded text-xs bg-blue hover:bg-blue-dark">View</a>
</td>
</tr>
<tr class="hover:bg-grey-lighter">
<td class="py-4 px-6 border-b border-grey-light">Paris</td>
<td class="py-4 px-6 border-b border-grey-light">
<a href="#" class="text-grey-lighter font-bold py-1 px-3 rounded text-xs bg-green hover:bg-green-dark">Edit</a>
<a href="#" class="text-grey-lighter font-bold py-1 px-3 rounded text-xs bg-blue hover:bg-blue-dark">View</a>
</td>
</tr>
<tr class="hover:bg-grey-lighter">
<td class="py-4 px-6 border-b border-grey-light">London</td>
<td class="py-4 px-6 border-b border-grey-light">
<a href="#" class="text-grey-lighter font-bold py-1 px-3 rounded text-xs bg-green hover:bg-green-dark">Edit</a>
<a href="#" class="text-grey-lighter font-bold py-1 px-3 rounded text-xs bg-blue hover:bg-blue-dark">View</a>
</td>
</tr>
<tr class="hover:bg-grey-lighter">
<td class="py-4 px-6 border-b border-grey-light">Oslo</td>
<td class="py-4 px-6 border-b border-grey-light">
<a href="#" class="text-grey-lighter font-bold py-1 px-3 rounded text-xs bg-green hover:bg-green-dark">Edit</a>
<a href="#" class="text-grey-lighter font-bold py-1 px-3 rounded text-xs bg-blue hover:bg-blue-dark">View</a>
</td>
</tr>
<tr class="hover:bg-grey-lighter">
<td class="py-4 px-6 border-b border-grey-light">Mexico City</td>
<td class="py-4 px-6 border-b border-grey-light">
<a href="#" class="text-grey-lighter font-bold py-1 px-3 rounded text-xs bg-green hover:bg-green-dark">Edit</a>
<a href="#" class="text-grey-lighter font-bold py-1 px-3 rounded text-xs bg-blue hover:bg-blue-dark">View</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
How to make a 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 make a Table component
w-2/3
mx-auto
bg-white
my-6
text-left
w-full
border-collapse
py-4
px-6
bg-grey-lightest
text-sm
text-grey-dark
border-b
border-grey-light
hover:bg-grey-lighter
text-grey-lighter
py-1
px-3
text-xs
bg-green
hover:bg-green-dark
bg-blue
hover:bg-blue-dark
23 steps to make a Table component with Tailwind CSS
Use
w-2/3
to set an element to a fixed width(2/3).Control the horizontal margin of an element to auto using the
mx-auto
utilities.Control the background color of an element to white using the
bg-white
utilities.Control the vertical margin of an element to 1.5rem using the
my-6
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 border color of an element to collapse using the
border-collapse
utilities.Control the vertical padding of an element to 1rem using the
py-4
utilities.Control the horizontal padding of an element to 1.5rem using the
px-6
utilities.Control the background color of an element to grey-lightest using the
bg-grey-lightest
utilities.Control the text color of an element to sm using the
text-sm
utilities.Control the text color of an element to grey-dark using the
text-grey-dark
utilities.Control the border color of an element to b using the
border-b
utilities.Control the border color of an element to grey-light using the
border-grey-light
utilities.Control the background color of an element to grey-lighter using the
hover:bg-grey-lighter
utilities on hover.Control the text color of an element to grey-lighter using the
text-grey-lighter
utilities.Control the vertical padding of an element to 0.25rem using the
py-1
utilities.Control the horizontal padding of an element to 0.75rem using the
px-3
utilities.Control the text color of an element to xs using the
text-xs
utilities.Control the background color of an element to green using the
bg-green
utilities.Control the background color of an element to green-dark using the
hover:bg-green-dark
utilities on hover.Control the background color of an element to blue using the
bg-blue
utilities.Control the background color of an element to blue-dark using the
hover:bg-blue-dark
utilities on hover.
Conclusion
The above is a step-by-step tutorial on how to use Tailwind CSS to make a Table components, learn and follow along to implement your own components.