DEV Community

TenE
TenE

Posted on

1

How to Use Tailwind CSS with Vanilla HTML, CSS, and JavaScript

Hey there! Want to style your website quickly without writing tons of custom CSS? Tailwind CSS has got you covered! It's a utility first framework that scans your HTML, JavaScript, and templates for class names, generates styles, and compiles them into a neat CSS file. Plus, it's super fast and flexible!

Getting Started with Tailwind CSS

The simplest and fastest way to get up and running with Tailwind CSS from scratch is with the Tailwind CLI tool. The CLI is also available as a standalone executable if you want to use it without installing Node.js.

Step 1: Install Tailwind CSS

First, open your terminal and run:

npm install tailwindcss @tailwindcss/cli
Enter fullscreen mode Exit fullscreen mode

This installs Tailwind and its CLI tool so you can start using it right away.

Step 2: Import Tailwind in Your CSS

Next, create a CSS file (letโ€™s call it src/input.css) and add these lines:

@import "tailwindcss";
Enter fullscreen mode Exit fullscreen mode

This ensures that all the essential styles are included in your project.

Step 3: Generate Your Tailwind CSS File

Now, letโ€™s tell Tailwind to scan your files and generate the final CSS:

npx tailwindcss -i ./src/input.css -o ./src/output.css --watch
Enter fullscreen mode Exit fullscreen mode

This command watches for any changes in your files and updates your CSS automatically. No more manual updates nice, right? ๐Ÿ˜ƒ

Step 4: Link Tailwind in Your HTML

Last step! Add your newly generated CSS file to your HTML so you can start using Tailwindโ€™s classes right away.

Example index.html:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Tailwind CSS with Vanilla HTML</title>
  <link href="./output.css" rel="stylesheet">
</head>
<body>
  <h1 class="text-3xl font-bold underline">
    Hello, Tailwind CSS! ๐ŸŽ‰
  </h1>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Why You'll Love Tailwind CSS

  • ๐Ÿš€ Fast Development โ€“ No need to write custom CSS; just use utility classes.
  • ๐ŸŽจ Highly Customizable โ€“ Configure styles with Tailwindโ€™s easy-to-use settings.
  • ๐Ÿ“ฑ Mobile-Friendly โ€“ Responsive design is built right in!
  • ๐Ÿ”ฅ Optimized Performance โ€“ Unused styles are removed, keeping your CSS lightweight.

Wrap-Up

And thatโ€™s it! ๐ŸŽ‰ With just a few simple steps, you now have Tailwind CSS set up with vanilla HTML, CSS, and JavaScript. Now you can enjoy fast and flexible styling for your web projects. Give it a try, and let me know what cool designs you come up with!

Happy coding! ๐Ÿ˜ƒ

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (2)

Collapse
 
maxart2501 profile image
Massimo Artizzu โ€ข
  • ๐Ÿš€ Fast Development โ€“ No need to write custom CSS; just use utility classes.

... in custom unstructured sequences of custom class names.

  • ๐ŸŽจ Highly Customizable โ€“ Configure styles with Tailwindโ€™s easy-to-use settings.

... which are nothing more than plain CSS custom properties.

  • ๐Ÿ“ฑ Mobile-Friendly โ€“ Responsive design is built right in!

... which does not actually mean "responsiveness", but rather "presets for arbitrarily defined breakpoints in a Bootstrap-era fashion that still don't get what a breakpoint actually is."

  • ๐Ÿ”ฅ Optimized Performance โ€“ Unused styles are removed, keeping your CSS lightweight.

... which has basically never been a performance problem.

Collapse
 
tene profile image
TenE โ€ข

Thanks for your detailed thoughts!

Tiugo image

Fast, Lean, and Fully Extensible

CKEditor 5 is built for developers who value flexibility and speed. Pick the features that matter, drop the ones that donโ€™t and enjoy a high-performance WYSIWYG that fits into your workflow

Start now

AWS Security LIVE! From re:Inforce 2025

Tune into AWS Security LIVE! streaming live from the AWS re:Inforce expo floor in Philadelphia from 8:00AM ET-6:00PM ET.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. โค๏ธ