Published on

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

Tags
Table

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

  1. Use w-2/3 to set an element to a fixed width(2/3).

  2. Control the horizontal margin of an element to auto using the mx-auto utilities.

  3. Control the background color of an element to white using the bg-white utilities.

  4. Control the vertical margin of an element to 1.5rem using the my-6 utilities.

  5. Control the text color of an element to left using the text-left utilities.

  6. Use w-full to set an element to a 100% based width.

  7. Control the border color of an element to collapse using the border-collapse utilities.

  8. Control the vertical padding of an element to 1rem using the py-4 utilities.

  9. Control the horizontal padding of an element to 1.5rem using the px-6 utilities.

  10. Control the background color of an element to grey-lightest using the bg-grey-lightest utilities.

  11. Control the text color of an element to sm using the text-sm utilities.

  12. Control the text color of an element to grey-dark using the text-grey-dark utilities.

  13. Control the border color of an element to b using the border-b utilities.

  14. Control the border color of an element to grey-light using the border-grey-light utilities.

  15. Control the background color of an element to grey-lighter using the hover:bg-grey-lighter utilities on hover.

  16. Control the text color of an element to grey-lighter using the text-grey-lighter utilities.

  17. Control the vertical padding of an element to 0.25rem using the py-1 utilities.

  18. Control the horizontal padding of an element to 0.75rem using the px-3 utilities.

  19. Control the text color of an element to xs using the text-xs utilities.

  20. Control the background color of an element to green using the bg-green utilities.

  21. Control the background color of an element to green-dark using the hover:bg-green-dark utilities on hover.

  22. Control the background color of an element to blue using the bg-blue utilities.

  23. 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.