Blog

Tailwind CSS

Styling with Tailwind CSS: utility classes, responsive layouts, dark mode and custom themes, with practical patterns for building clean interfaces quickly.

No stories here just yet!

We have not written about this yet. Please explore another topic, or come back soon!

Questions about this topic

Quick, clear answers to what readers ask most about this topic.

What is Tailwind CSS?

Tailwind CSS is a utility-first CSS framework that styles a page with small single-purpose classes written directly in the HTML. Classes like p-4, text-center and bg-blue-500 each set one style. Developers combine these classes to build any design without writing much custom CSS.

What does utility-first CSS mean?

Utility-first CSS means building a design from many small classes that each do one thing, instead of writing a custom class for every component. A button gets its look from classes for padding, colour, border radius and font weight. This approach keeps styles close to the markup and avoids large stylesheets that keep growing.

Why do developers choose Tailwind CSS over plain CSS?

Developers choose Tailwind CSS because it speeds up styling and keeps the final CSS file small. There is no need to invent class names or switch between HTML and CSS files for every change. Tailwind CSS also gives a consistent scale for spacing, colours and font sizes, which keeps a design tidy.

What is the difference between Tailwind CSS and Bootstrap?

Tailwind CSS gives low-level utility classes to build a custom design, while Bootstrap gives ready-made components like navbars, cards and modals. Bootstrap is faster for a standard look with little design work. Tailwind CSS is better when a project needs its own unique design without fighting a default theme.

How do I install Tailwind CSS in a project?

Tailwind CSS is installed through npm and connected to the project's build tool, such as Vite, PostCSS or the Tailwind CLI. In Tailwind CSS version 4, you add the package, then import it at the top of your main CSS file with @import "tailwindcss". The official installation guide has short steps for each common framework, including Laravel, Next.js and Vite.

Is Tailwind CSS good for beginners?

Tailwind CSS is fine for beginners who already understand basic CSS properties like margin, padding, flexbox and grid. Each Tailwind class maps to a real CSS property, so learning CSS first makes the classes easy to read. Beginners who skip CSS basics often struggle to fix layouts in Tailwind CSS.

How long does it take to learn Tailwind CSS?

Most developers who know CSS can become productive with Tailwind CSS in a few days. The class names follow clear patterns, so learning one group of classes helps guess the rest. Mastering responsive variants, custom themes and component patterns takes a few weeks of real use.

How does responsive design work in Tailwind CSS?

Responsive design in Tailwind CSS works by adding breakpoint prefixes like sm:, md: and lg: in front of any utility class. Tailwind CSS is mobile-first, so a class without a prefix applies to all screens, and a prefixed class applies from that breakpoint upward. For example, text-sm md:text-lg gives small text on phones and larger text on wider screens.

What are the default breakpoints in Tailwind CSS?

The default breakpoints in Tailwind CSS are sm at 640 pixels, md at 768 pixels, lg at 1024 pixels, xl at 1280 pixels and 2xl at 1536 pixels. Each breakpoint is a minimum width, which matches Tailwind's mobile-first approach. A project can change these values or add new breakpoints in its theme settings.

How do I add dark mode with Tailwind CSS?

You add dark mode in Tailwind CSS by putting the dark: prefix in front of any class, such as dark:bg-gray-900. By default, Tailwind CSS follows the visitor's operating system setting. To let users switch dark mode with a button, you configure the dark variant to depend on a class or data attribute on the page.

How do I customize colours and fonts in Tailwind CSS?

In Tailwind CSS version 4, you customize colours and fonts with CSS variables inside an @theme block in your main CSS file. A variable like --color-brand creates classes such as bg-brand and text-brand automatically. Older versions used a tailwind.config.js file for the same job, and that approach still works in version 4 through a compatibility option.

Does Tailwind CSS make HTML messy?

Tailwind CSS can make HTML look busy, because one element may carry many classes. Most teams solve this by turning repeated patterns into components in their framework, such as a Blade, React or Vue component. The trade-off is that styles stay visible next to the markup, which makes changes quick and safe.

How does Tailwind CSS keep the CSS file small?

Tailwind CSS keeps the CSS file small by scanning the project's files and generating only the classes that are actually used. Unused utilities never reach the final stylesheet. A typical production CSS file built with Tailwind CSS is small, even for large sites.

What is the @apply directive in Tailwind CSS?

The @apply directive in Tailwind CSS lets you use Tailwind utility classes inside your own CSS rules. It is handy for styling content you do not control, such as HTML produced by a text editor. The Tailwind team recommends using it sparingly, since components are usually a cleaner way to reuse styles.

Can I use Tailwind CSS with Laravel?

Yes, Tailwind CSS works well with Laravel, and new Laravel projects come set up to use it with Vite. You write Tailwind classes in Blade templates, and Vite builds the final CSS. Laravel's starter kits also use Tailwind CSS for their login and dashboard screens.

Can I use Tailwind CSS with React or Vue?

Yes, Tailwind CSS works with React, Vue, Svelte and most other JavaScript frameworks. The classes go in the component's markup through className in React or class in Vue. Because each component holds its own classes, Tailwind CSS fits well with component-based frameworks.

Is Tailwind CSS good for SEO?

Tailwind CSS has no direct effect on search ranking, but it can help SEO indirectly by keeping the CSS file small and pages fast. Page speed is part of Google's page experience signals. The content, page structure and HTML semantics still matter far more than the styling tool.

What are arbitrary values in Tailwind CSS?

Arbitrary values in Tailwind CSS let you use an exact value that is not in the theme by writing it in square brackets. For example, w-[37%] or top-[117px] creates a class for that exact value on the spot. Arbitrary values are useful for one-off cases, but a value used often belongs in the theme.

How do hover and focus states work in Tailwind CSS?

Hover and focus states in Tailwind CSS work by adding a state prefix like hover:, focus: or active: before a utility class. For example, bg-blue-500 hover:bg-blue-600 darkens a button when the mouse is over it. Prefixes can be combined with breakpoints and dark mode, such as md:hover:underline.

Does Tailwind CSS include ready-made components?

No, Tailwind CSS itself includes only utility classes, not ready-made components like modals or navbars. Ready components come from separate collections, such as the official Tailwind Plus or community libraries like daisyUI and Flowbite. Many teams build their own small component set on top of the utilities.

Can Tailwind CSS build right-to-left layouts for Arabic?

Yes, Tailwind CSS supports right-to-left layouts through the rtl: and ltr: variants and logical utility classes. Logical classes like ms-4 and pe-2 set margin and padding at the start or end of a line, so they flip automatically in Arabic. This makes one set of markup work for both English and Arabic pages.

What changed in Tailwind CSS version 4?

Tailwind CSS version 4 moved configuration into CSS with the @theme block and a single @import line. Version 4 also brought a faster build engine, automatic detection of content files and modern CSS features like cascade layers. Most projects upgrading from version 3 can use the official upgrade tool to update their code.

When should I not use Tailwind CSS?

You may not want Tailwind CSS when a project needs a full set of ready components with almost no custom design, or when the team prefers writing classic CSS. A small static page with a few styles may not need any framework at all. Tailwind CSS pays off most on projects with custom designs that keep growing.

How do I keep Tailwind CSS classes organized?

You keep Tailwind CSS classes organized by turning repeated patterns into components and by sorting classes in a consistent order. The official Prettier plugin for Tailwind CSS sorts classes automatically on save. Defining brand colours and spacing in the theme also keeps classes short and consistent.

Is Tailwind CSS free to use in commercial projects?

Yes, Tailwind CSS is open source under the MIT license, so it can be used in personal and commercial projects. The license allows using, changing and shipping Tailwind CSS in any product. The source code is public on GitHub, where anyone can read it and report problems.