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! πŸ˜ƒ

Neon image

Serverless Postgres in 300ms (❗️)

10 free databases with autoscaling, scale-to-zero, and read replicas. Start building without infrastructure headaches. No credit card needed.

Try for Free β†’

Top comments (1)

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.

AI Agent image

How to Build an AI Agent with Semantic Kernel (and More!)

Join Developer Advocate Luce Carter for a hands-on tutorial on building an AI-powered dinner recommendation agent. Discover how to integrate Microsoft Semantic Kernel, MongoDB Atlas, C#, and OpenAI for ingredient checks and smart restaurant suggestions.

Watch the video πŸ“Ί

πŸ‘‹ Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay