Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Skriptmonkey
Skriptmonkey

Posted on • Originally published atexperiencednovice.dev

     

TailwindCSS: Quick Setup

Introduction

TailwindCSS is a utility-first CSS framework that allows you to style your HTML without needing to leave your HTML file. Most of the styling is done though pre-defined CSS classes. This results in a very easy system to use when adding style to your website.

This quick setup guide will get you to a point where you can start writing HTML and adding in CSS as you go.

If you're in a bit hurry and willing to sacrifice some features you can use theTailwindCSS CDN.

Installing Node.js

This guide is written with Linux in mind but you can also install Nodejs on Windows and Mac.

For RHEL based distros (Fedora, CentOS, Rocky Linux, etc..):

$ sudo dnf install nodejs
Enter fullscreen modeExit fullscreen mode

For Ubuntu based distros you can install Node fromNodeSource:

$ curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -$ sudo apt-get install -y nodejs
Enter fullscreen modeExit fullscreen mode

Setup the Project environment

Now that we have Node installed, lets create our project environment.

First, cd into your workspace. I like to use~/Code as my main local workspace.

$ cd ~/Code
Enter fullscreen modeExit fullscreen mode

Create a folder of us to work in and cd into that.

$ mkdir tailwind$ cd tailwind
Enter fullscreen modeExit fullscreen mode

Initialize the directory for NPM. This will create apackage.json file within the folder.

$ npm init -y
Enter fullscreen modeExit fullscreen mode

Now install TailwindCSS.

$ npm install tailwindcss
Enter fullscreen modeExit fullscreen mode

To finish off this environment, lets create asrc andpublic folder. You can name these folders whatever you want.

$ mkdir src public
Enter fullscreen modeExit fullscreen mode

Generating the TailwindCSS CSS file

Next lets create a style.css file.

$ touch src/style.css
Enter fullscreen modeExit fullscreen mode

Then, using your preferred text editor, add the@tailwind directives so your style.css file looks like this:

@tailwind base;@tailwind components;@tailwind utilities;
Enter fullscreen modeExit fullscreen mode

Now, open thepackage.json file and add a new command to the scripts. The file should look like this.

{  "name": "tailwind",  "version": "1.0.0",  "description": "",  "main": "index.js",  "scripts": {    "dev": "tailwind build -i src/style.css -o public/tailwind.css --watch"  },  "keywords": [],  "author": "",  "license": "ISC",  "dependencies": {    "tailwindcss": "^3.0.1"  }}
Enter fullscreen modeExit fullscreen mode

Finally, create atailwind.config.js file in your project root folder containing the following.

module.exports = {  content: ["./public/**/*.{html,js}"],  theme: {    extend: {},  },  plugins: [],}
Enter fullscreen modeExit fullscreen mode

Remember the "dev" script that we added into thepackage.json file? Now we're going to run it in a separate terminal.

$ npm run dev
Enter fullscreen modeExit fullscreen mode

This command will continue to run while you write your HTML. It will "watch" and "rebuild" your tailwind.css file as new utility classes are added into your HTML file. If you'd like to learn more about the Just-in-Time engine, check out thisblog post.

You should now have a new tailwind.css file in the public folder. link this file into your HTML file and start coding away. Remember to keep thenpm run dev command running in a separate terminal.

Using the style.css file

Now you can use the style.css file by adding a link tag into the<head> of your html source file.

<link href="./style.css" rel="stylesheet">
Enter fullscreen modeExit fullscreen mode

Enjoy the new setup and happy coding!

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

  • Location
    Alaska
  • Education
    Some College. Studied Computer Science at University of Alaska Anchorage.
  • Pronouns
    He/Him
  • Work
    Systems Engineer at Resource Data Inc.
  • Joined

Trending onDEV CommunityHot

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp