>_ DevTrendsen

Language

Home

Languages

Sections

Frontend Backend Mobile DevOps AI / ML GameDev Blockchain Embedded Security
JavaScript

daisyUI Turns Tailwind CSS's Mile-Long Classes into Neat Components

daisyUI logo

Anyone who's built interfaces with Tailwind CSS knows this pain. You open a markup file and a regular button takes up four lines of code. Dozens of classes: padding, border radius, backgrounds, hover states, focus states, and active press states.

On one hand, the utilitarian approach gives you full control over styles. On the other hand, reading such markup a couple of months later is painfully difficult.

The daisyUI library solves exactly this problem. It brings back familiar semantic classes like btn, card, or modal to Tailwind, while preserving configuration flexibility.

What's Under the Hood

The project was created and is maintained by developer Pouya Saadeghi. The repository has already collected over 42 thousand stars on GitHub. Currently, the library is actively being updated to the fifth major version.

Essentially, daisyUI works as a plugin for Tailwind CSS. The main feature is that there's no JavaScript underneath. It's pure CSS. This makes components easy to integrate anywhere: in React, Vue, Svelte, Angular, or regular server-side templates with Django, Laravel, and Go.

If you need a dropdown or modal window, they work on native HTML elements <dialog> and <details> or via CSS selectors. You write the state management logic yourself using whatever stack you're already using in the project.

How daisyUI Differs from Other UI Libraries

Let's compare the markup of a regular button. In plain Tailwind, a basic blue button requires writing a long chain:

<button class="inline-flex items-center justify-center px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white font-medium rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 transition-colors">
  Сохранить
</button>

In daisyUI, the same result is achieved much more concisely:

<button class="btn btn-primary">
  Сохранить
</button>

At the same time, nothing prevents you from selectively overriding any parameter with a familiar Tailwind utility. Want to make the button slightly wider or reset the shadow? Just add w-full or shadow-none directly to the class attribute.

Main Features

The library offers several nice things right out of the box.

Ready-made semantic components. The catalog contains about fifty ready-made elements: tables, badges, pagination, accordions, breadcrumbs, and input forms. The markup stays clean, and layout speeds up.

Built-in theming system. The project has over 30 built-in design themes, including dark, light, retro, and cyberpunk. Switching themes is as simple as setting one HTML attribute:

<html data-theme="dark">

You can configure your own color palette through CSS variables in the configuration file, without rewriting the styles of each individual element.

Bundle size savings. Since this is a Tailwind plugin, the bundler removes all unused selectors. Only the CSS that actually appears in your templates makes it to production.

Where the Library Works Best

daisyUI comes in handy in several scenarios:

  1. Rapid prototyping and MVP. When you need to assemble a working admin panel or personal account interface in a couple of evenings, without spending hours aligning each input.
  2. Server-side rendering projects and HTMX. Since no JS runtime is required, components fit perfectly into monolithic applications with Go, Python, or Ruby.
  3. Pet projects. A great way to get a tidy design without hiring a designer.

The Fly in the Ointment

If you're working on a project with complex, unique design mockups from a studio, daisyUI's default styles might get in the way. You'll find yourself constantly overriding base border radii or internal padding of components. In such situations, it's easier to write in plain Tailwind or use headless libraries like Radix UI or Headless UI.

daisyUI strikes a good balance between interface build speed and markup cleanliness. If you like the Tailwind concept but are frustrated by the endless stream of utility classes in your code, the project is definitely worth testing in your next pet project or admin panel.

Installation takes a couple of minutes via npm i -D daisyui@latest, after which the plugin is simply added to the style config.

Related projects