How to Create Tailwind CSS tables
Tags: tailwindcss, css, webdev, codenewbie
Published: 2021-11-04 13:54:55

---
title: How to Create Tailwind CSS tables
published: true
date: 2021-01-10 01:16:04 UTC
tags: ["tailwindcss", "css", "webdev", "codenewbie"]
canonical_url: https://www.devwares.com/blog//how-to-create-tailwind-css-tables
cover_image: https://www.devwares.com/blog/images/how-to-create-tailwind-css-tables.png
---

## Introduction

Using Tailwind CSS to create UI components is easy. Tailwind CSS is the first utility CSS framework that allows you, to use low-level utility classes to build fast UI.

Setting up some of these components can be easy and will make it possible for you to use the CSS framework without worrying about fighting it. You can check out some advantages of this framework here.

However, we will use Tailwind CSS to build some tables. Tailwind CSS tables require a bit of code to set it up and may seem complicated. But its really not.

It's as easy as possible and, I will walk you through some Tailwind CSS tables you can start within your projects.

## Table of Content

- Where to start
- Installing a Tailwind CSS to your project
- Building the first table
- Building the second table
- Building the third table
- Conclusion

## Where to start

We will start by creating a project directory.

**Code:**

```javascript
mkdir build-Tailwind-tables & cd build-Tailwind-tables
```

The code above will create an empty directory and also direct you to the directory. These will become your current working directory. At this stage we can now initialize our project by writing this code.

**Code:**

```javascript
npm init -y.
```

this will create a package.json file on the current directory.

## Installing Tailwind CSS

At this stage we can go ahead to install tailwind css to our project. We can do this by running the following code. Using npm .

**Code:**

```javascript
npm install tailwindcss.
```

when using yarn

**Code:**

```javascript
yarn add tailwindcss.
```

We can go ahead to create a style sheet file at this stage. This style sheet file is where we will compile our tailwind.css file into using the tailwind TLC tool. We can call this style sheet file style.css.

Inside the tailwind.css file we will use @tailwind directive to inject tailwind’s base, components and utilities. Like the code below

```css
@tailwind base;
@tailwind components;
@tailwind utilities;
```

For some of us that might wish to customize their tailwind css utilities. This can be done by writing the following code on the terminal.

**Code:**

```javascript
npx tailwindcss init
```

The command above will automatically generate a tailwind.config.js file. This file is where you can modify or customize any utility on tailwind. The generated file will look like the code below.

**Code:**

```javascript
module.exports = {
  theme: {
    extend: {},
  },
  variants: {
    extend: {},
  },
  plugins: [],
};
```

The next thing to do is to process our CSS. We can do this by running the following command on our terminal

**Code:**

```javascript
npx tailwindcss build styles.css -o tailwind.css.
```

The code above will generate our tailwind css codes and will get the project ready for you.

## Building the table

After the installation of tailwind css. The next thing we are to do is to create an index.html file. Inside the html file we will write the following code

**Code:**

```html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Tailwind tables</title>
    <link rel="stylesheet" href="style.css" />
  </head>
  <body></body>
</html>
```

The code above is a HTML template which contains the link to the processed Tailwind CSS. We linked the style.css to our HTML template to enable us use Tailwind CSS utilities in our code.

## Adding the styles.

We can now go ahead to code the body of the table and add some tailwind CSS utility styles.

**Code:**

```html
<div class="container flex justify-center mx-auto">
  <div class="flex flex-col">
    <div class="w-full">
      <div class="border-b border-gray-200 shadow">
        <table class="divide-y divide-green-400 ">
          <thead class="bg-gray-50">
            <tr>
              <th class="px-6 py-2 text-xs text-gray-500">
                ID
              </th>
              <th class="px-6 py-2 text-xs text-gray-500">
                Name
              </th>
              <th class="px-6 py-2 text-xs text-gray-500">
                Email
              </th>
              <th class="px-6 py-2 text-xs text-gray-500">
                Created_at
              </th>
              <th class="px-6 py-2 text-xs text-gray-500">
                Edit
              </th>
              <th class="px-6 py-2 text-xs text-gray-500">
                Delete
              </th>
            </tr>
          </thead>
          <tbody class="bg-white divide-y divide-gray-300">
            <tr class="whitespace-nowrap">
              <td class="px-6 py-4 text-sm text-gray-500">
                1
              </td>
              <td class="px-6 py-4">
                <div class="text-sm text-gray-900">
                  Adam joe
                </div>
              </td>
              <td class="px-6 py-4">
                <div class="text-sm text-gray-500">adamjoe@example.com</div>
              </td>
              <td class="px-6 py-4 text-sm text-gray-500">
                2021-12-12
              </td>
              <td class="px-6 py-4">
                <a href="#">
                  <svg
                    xmlns="http://www.w3.org/2000/svg"
                    class="w-6 h-6 text-blue-400"
                    fill="none"
                    viewBox="0 0 24 24"
                    stroke="currentColor"
                  >
                    <path
                      stroke-linecap="round"
                      stroke-linejoin="round"
                      stroke-width="2"
                      d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"
                    />
                  </svg>
                </a>
              </td>
              <td class="px-6 py-4">
                <a href="#">
                  <svg
                    xmlns="http://www.w3.org/2000/svg"
                    class="w-6 h-6 text-red-400"
                    fill="none"
                    viewBox="0 0 24 24"
                    stroke="currentColor"
                  >
                    <path
                      stroke-linecap="round"
                      stroke-linejoin="round"
                      stroke-width="2"
                      d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"
                    />
                  </svg>
                </a>
              </td>
            </tr>
            <tr class="whitespace-nowrap">
              <td class="px-6 py-4 text-sm text-gray-500">
                2
              </td>
              <td class="px-6 py-4">
                <div class="text-sm text-gray-900">
                  Jon doe
                </div>
              </td>
              <td class="px-6 py-4">
                <div class="text-sm text-gray-500">jhondoe@example.com</div>
              </td>
              <td class="px-6 py-4 text-sm text-gray-500">
                2021-1-12
              </td>
              <td class="px-6 py-4">
                <a href="#">
                  <svg
                    xmlns="http://www.w3.org/2000/svg"
                    class="w-6 h-6 text-blue-400"
                    fill="none"
                    viewBox="0 0 24 24"
                    stroke="currentColor"
                  >
                    <path
                      stroke-linecap="round"
                      stroke-linejoin="round"
                      stroke-width="2"
                      d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"
                    />
                  </svg>
                </a>
              </td>
              <td class="px-6 py-4">
                <a href="#">
                  <svg
                    xmlns="http://www.w3.org/2000/svg"
                    class="w-6 h-6 text-red-400"
                    fill="none"
                    viewBox="0 0 24 24"
                    stroke="currentColor"
                  >
                    <path
                      stroke-linecap="round"
                      stroke-linejoin="round"
                      stroke-width="2"
                      d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"
                    />
                  </svg>
                </a>
              </td>
            </tr>
            <tr class="whitespace-nowrap">
              <td class="px-6 py-4 text-sm text-gray-500">
                3
              </td>
              <td class="px-6 py-4">
                <div class="text-sm text-gray-900">
                  Emily chan
                </div>
              </td>
              <td class="px-6 py-4">
                <div class="text-sm text-gray-500">emilychan@example.com</div>
              </td>
              <td class="px-6 py-4 text-sm text-gray-500">
                2021-1-12
              </td>
              <td class="px-6 py-4">
                <a href="#">
                  <svg
                    xmlns="http://www.w3.org/2000/svg"
                    class="w-6 h-6 text-blue-400"
                    fill="none"
                    viewBox="0 0 24 24"
                    stroke="currentColor"
                  >
                    <path
                      stroke-linecap="round"
                      stroke-linejoin="round"
                      stroke-width="2"
                      d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"
                    />
                  </svg>
                </a>
              </td>
              <td class="px-6 py-4">
                <a href="#">
                  <svg
                    xmlns="http://www.w3.org/2000/svg"
                    class="w-6 h-6 text-red-400"
                    fill="none"
                    viewBox="0 0 24 24"
                    stroke="currentColor"
                  >
                    <path
                      stroke-linecap="round"
                      stroke-linejoin="round"
                      stroke-width="2"
                      d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"
                    />
                  </svg>
                </a>
              </td>
            </tr>
            <tr class="whitespace-nowrap">
              <td class="px-6 py-4 text-sm text-gray-500">
                4
              </td>
              <td class="px-6 py-4">
                <div class="text-sm text-gray-900">
                  susan coby
                </div>
              </td>
              <td class="px-6 py-4">
                <div class="text-sm text-gray-500">susancoby@example.com</div>
              </td>
              <td class="px-6 py-4 text-sm text-gray-500">
                2021-1-12
              </td>
              <td class="px-6 py-4">
                <a href="#">
                  <svg
                    xmlns="http://www.w3.org/2000/svg"
                    class="w-6 h-6 text-blue-400"
                    fill="none"
                    viewBox="0 0 24 24"
                    stroke="currentColor"
                  >
                    <path
                      stroke-linecap="round"
                      stroke-linejoin="round"
                      stroke-width="2"
                      d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"
                    />
                  </svg>
                </a>
              </td>
              <td class="px-6 py-4">
                <a href="#">
                  <svg
                    xmlns="http://www.w3.org/2000/svg"
                    class="w-6 h-6 text-red-400"
                    fill="none"
                    viewBox="0 0 24 24"
                    stroke="currentColor"
                  >
                    <path
                      stroke-linecap="round"
                      stroke-linejoin="round"
                      stroke-width="2"
                      d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"
                    />
                  </svg>
                </a>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>
```

Our webpage will look like the image below.

![Tables](https://www.devwares.com/static/942009191199c469fbd4698bd43542df/4e6ec/tailwind-css-table.png)

###Conclusion

Tailwind CSS utilities make it easy to build beautiful tables for your webpage. We looked at how we can use Tailwind CSS to build beautiful tables and install Tailwind CSS to your project. By now, you should be able to use Tailwind CSS to build beautiful tables.



## Design and code tailwind css websites 3x faster

We created a tool to visually build tailwind css components, prototypes, websites, and webapps. Ship projects faster using an intuitive tailwind builder and editor.[Try Windframe out for free.](https://www.devwares.com/windframe)

![WINDFRAME](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h8w3qu4a93bdkhtjnhbh.png)

## Resources 

- [Get Contrast PRO](https://www.devwares.com/product/bootstrap-contrast-pro)

- [How to use tailwind CSS in HTML]  (https://www.devwares.com/blog/how-to-use-tailwind-css-in-HTML)

- [Why tailwind CSS is good](https://www.devwares.com/blog/why-tailwind-css-is-good)

- [How to use Tailwind CSS in Nextjs](https://www.devwares.com/blog/tailwind-css-in-nextjs)

- [How to create Tailwind CSS Components for your Website](https://www.devwares.com/blog/how-to-create-tailwind-css-components-for-your-website)

- [How to create Tailwind CSS Animation](https://www.devwares.com/blog/create-animation-with-tailwind-css/)

- [Tailwind grid-How to use tailwind CSS grid templates in your project](https://www.devwares.com/blog/how-to-add-tailwind-css-grid-to-your-project/)

- [How to create a Beautiful Responsive Navigation bar Using Tailwind CSS](https://www.devwares.com/blog/how-to-create-a-beautiful-responsive-navbar-using-tailwind-css/)

- [Tailwind form-How to create and style a Responsive Form using Tailwind CSS](https://www.devwares.com/blog/how-to-create-and-style-a-responsive-form-using-tailwindcss/)

- [Tailwind CSS Flex: How to use Tailwind CSS Flex](https://www.devwares.com/blog/how-to-use-tailwind-css-flex/)

- [How to use tailwind CSS padding, margin and border in your project](https://www.devwares.com/blog/how-to-use-tailwind-css-padding-margin-and-border-in-your-project/)

- [Tailwind CSS CDN-How to use the Tailwind CSS JIT CDN](https://www.devwares.com/blog/how-to-use-the-tailwind-css-JIT-CDN/)

- [How to set up your first Tailwind CSS Project](https://www.devwares.com/blog/setting-up-your-first-project-using-tailwind-css/)

- [How to use Tailwind CSS in HTML](https://www.devwares.com/blog/how-to-use-tailwind-css-in-HTML/)

- [Tailwind CSS table-How to Create Tailwind CSS tables](https://www.devwares.com/blog/how-to-create-tailwind-css-tables/)

- [How to set up your first Tailwind CSS Project](https://www.devwares.com/blog/setting-up-your-first-project-using-tailwind-css/)

- [Why is tailwind CSS better than other CSS framework](https://www.devwares.com/blog/why-tailwind-css-is-good/)

- [10 tailwind CSS templates and themes](https://www.devwares.com/blog/tailwind-css-10-templates-and-themes/)

- [How to add tailwind CSS colors and Fonts to your project](https://www.devwares.com/blog/how-to-add-tailwind-css-colors-and-fonts-to-your-project/)

- [Differences between Tailwind CSS and SASS](https://www.devwares.com/blog/differences-between-tailwind-css-and-sass/)

- [Differences Between Tailwind CSS and Bootstrap](https://www.devwares.com/blog/diffrences-between-tailwind-css-and-bootstrap/)

- [10 Awesome projects built with Tailwind CSS](https://www.devwares.com/blog/awesome-10-projects-built-with-tailwind/).

- [How to install Tailwind CSS in Vue.js](https://www.devwares.com/blog/how-to-install-tailwind-css-in-vuejs/).

- [How to use Tailwind CSS in React](https://www.devwares.com/blog/how-to-use-tailwind-css-in-react/)

- [How to install Tailwind CSS with Laravel](https://www.devwares.com/blog/how-to-install-tailwind-css-in-laravel/)

- [How to create react date picker](https://www.devwares.com/blog/create-datepicker-with-contrast/)

- [React bootstrap 5 form-How to create React forms](https://www.devwares.com/blog/how-to-create-and-style-a-responsive-form-using-tailwindcss/).

- [How to create a beautiful React multiselect](https://www.devwares.com/blog/create-multiselect-with-contrast/).

- [How to create a beautiful React Bootstrap progress bar](https://www.devwares.com/blog/create-progress-with-contrast/).

- [How to create a beautiful React Bootstrap select with icons](https://www.devwares.com/blog/create-select-with-contrast/).

- [How to create a beautiful Bootstrap 5 stepper](https://www.devwares.com/blog/create-stepper-with-contrast/)

- [How to create a beautiful React Bootstrap table]
(https://www.devwares.com/blog/create-tables-with-contrast/)

- [How to create beautiful React Bootstrap tabs](https://www.devwares.com/blog/create-tabs-with-contrast/)

- [How to create a Beautiful Responsive Navigation bar Using Tailwind CSS](https://www.devwares.com/blog/how-to-create-a-beautiful-responsive-navbar-using-tailwind-css/)

- [Tailwind Modal-How to create a React Modal using Tailwind CSS.](https://www.devwares.com/blog/how-to-create-a-react-modal-using-tailwind-css/)

- [How to create a Bootstrap 5 Modal.](https://www.devwares.com/blog/how-to-create-a-bootstrap5-modal/)

- [How to create a beautiful Bootstrap Data table with Icons](https://www.devwares.com/blog/create-datatable-with-contrast/)

- [How to create a React date picker.](https://www.devwares.com/blog/create-datepicker-with-contrast/)

- [React bootstrap 5 form-How to create React forms](https://www.devwares.com/blog/create-forms-with-contrast/)

- [How to create a Angular Bootstrap Sidebar](https://www.devwares.com/blog/how-to-create-an-angular-bootstrap-sidebar/)

- [How to use Bootstrap in React Using a React Library](https://www.devwares.com/blog/using-bootstrap-in-react/)

- [How to Create React Tabs with Tailwind CSS](https://www.devwares.com/blog/how-to-create-react-tabs-with-tailwind-css/)

- [How to implement dark mode in React using tailwind css](https://www.devwares.com/blog/how-to-implement-dark-mode-in-tailwind-css/)

- [How to Implement a React Step Progress Bar Using Tailwind CSS](https://www.devwares.com/blog/how-to-implement-a-react-step-progress-bar-using-tailwind-css/)