# How to Setup Tailwind 3 on Rails

*Published on December 13, 2021*

---


_Update: Tailwind documentation has since added the_&nbsp;[_installation steps with Rails_](https://tailwindcss.com/docs/guides/ruby-on-rails)_._

Even though the official Tailwind documentation has&nbsp;[installation instructions](https://tailwindcss.com/docs/installation/framework-guides)&nbsp;for various client-side frameworks, it is missing one for Rails. Most of the tutorials work with the older versions of Tailwind. With&nbsp;[version 3](https://tailwindcss.com/blog/tailwindcss-v3)&nbsp;released a few days ago, I thought it’d be nice to have an up-to-date guide for Rails developers trying to set Tailwind 3 on a Rails app, so here it goes.

### Step 1: Install Tailwind CSS

Run the following command from the root directory of your Rails application, which installs the Tailwind package.

```bash
npm install -D tailwindcss
```

### Step 2: Initialize Tailwind

By default, Tailwind will look for a&nbsp;`tailwind.config.js`&nbsp;file at the root of your project where you can define any customizations. The following command generates a&nbsp;`tailwind.config.js`&nbsp;file in your Rails application.

```bash
npx tailwindcss init
```

### Step 3: Configure the source template paths

The content section is where you configure the paths to all of your HTML templates, JS components, and any other files that contain Tailwind class names.

Modify the generated&nbsp;`tailwind.config.js`&nbsp;file to include all the HTML, JS and ERB files under the&nbsp;`app`&nbsp;directory.

```javascript
module.exports = {
  content: ["./app/**/*.{html,js,erb}"],
  theme: {
    extend: {},
  },
  plugins: [],
}
```

### Step 4: Add Tailwind directives to the CSS

Tailwind is made up of a few different pieces: a reset stylesheet, the utility classes, and functions that make working with Tailwind easier.

In the&nbsp;`app/assets/stylesheets/application.css`&nbsp;file, add the following Tailwind directives.

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

### Step 5: Start the Tailwind CLI build process

Run the following command from the root directory of your Rails application. This will watch for the changes in the view files.

```bash
npx tailwindcss -i app/assets/stylesheets/application.css -o app/assets/stylesheets/wind.css --watch
```

### Step 6: Add Tailwind to the HTML

Finally, in the&nbsp;`application.html.erb`&nbsp;file, add the reference to the generated stylesheet file.

```html
<!DOCTYPE html>
<html>
<head>
  <title>Blog</title>
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <%= csrf_meta_tags %>
  <%= csp_meta_tag %>

  <%= stylesheet_link_tag 'wind', media: 'all', 'data-turbolinks-track': 'reload' %>
  <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
```

That’s it! You have now set up Tailwind in your Ruby on Rails application.

