Skip to main content

Tailwind CSS

Tailwind CSS is utility-first CSS framework that allows developers to rapidly build modern, responsive user interfaces by applying predefined utility classes directly within their HTML markup. It is not a traditional UI kit like Bootstrap that provides ready-made components, but rather a set of low-level classes for granular control over styling. 

Core Concepts
  • Utility-First Workflow: The fundamental principle of Tailwind is using small, single-purpose classes (e.g., bg-blue-500p-4text-xl) that correspond to one or two specific CSS properties and values. This approach means you rarely write custom CSS, working instead entirely within your HTML or component files.
  • Rapid Development: You save time by not having to come up with class names, switch between HTML and CSS files, or manage complex selector decisions. This significantly speeds up the design and prototyping process.
  • Consistency and Customization: While opinionated (it uses a predefined design system of color palettes, spacing scales, etc.), Tailwind is highly customizable via a configuration file (tailwind.config.js). This ensures visual consistency across a project while still allowing for a unique design tailored to specific brand guidelines.
  • Responsive Design and States: Tailwind uses simple prefixes to apply styles conditionally based on screen size (sm:md:lg:) or element states (hover:focus:dark:), making it easy to build fully responsive and interactive designs. It follows a mobile-first philosophy for responsive breakpoints.
  • Zero-Runtime: Tailwind scans your code for used classes and generates a static, optimized CSS file during the build process, resulting in a very small production file size. 

Example
Here is how you would create a styled button using Tailwind CSS, compared to traditional CSS:
Tailwind CSS (in HTML):

html
<button class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-full">
  Button
</button>
  • bg-blue-500: sets a blue background.
  • hover:bg-blue-700: changes to a darker blue on hover.
  • text-white: sets the text color to white.
  • font-bold: makes the text bold.
  • py-2 and px-4: add vertical and horizontal padding.
  • rounded-full: applies fully rounded corners. 
Traditional CSS (in a separate file):

css
.my-button {
  background-color: #4299e1; /* approximate blue-500 */
  color: white;
  font-weight: 700;
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
  padding-left: 1rem;
  padding-right: 1rem;
  border-radius: 9999px; /* full rounded */
}

.my-button:hover {
  background-color: #3182ce; /* approximate blue-700 */
}

Getting Started
You can experiment with Tailwind instantly without installation using the official Tailwind Play online editor, or follow the official Tailwind CSS documentation for installation guides tailored to specific frameworks like React, Vue, Next.js, and more