• HOME
  • SETUP
  • AI PROMPTS
  • APPS
  • ABOUT
  • BLOG
  • HOME
  • SETUP
  • AI PROMPTS
  • APPS
  • ABOUT
  • BLOG
Find Me Online
STAYCURIOUS
Privacy

© 2026 BERTA CODES

Back to blog
Tailwind CSSCSSBest Practices

Tailwind CSS Class Organization and Linting in 2025

A practical guide to Tailwind CSS class ordering, organization patterns, and linting tools.

March 12, 2025
Berta Matuliauskiene
6 min read
Tailwind CSS Class Organization and Linting in 2025

Tailwind CSS continues to dominate the utility-first CSS landscape in 2025. However, as projects grow in complexity, maintaining consistent class organization becomes crucial for readability and maintainability. This guide focuses on practical class organization strategies, ordering conventions, and essential linting tools with real-world examples.

Class Organization Principles Recommended Class Order

In 2025, the community has largely settled on a standard ordering convention for Tailwind classes to improve readability and maintainability:

  1. Layout & Position (flex, grid, absolute, etc.)
  2. Display & Visibility (block, hidden, etc.)
  3. Box Model (w-, h-, p-, m-, etc.)
  4. Typography (text-, font-, etc.)
  5. Visual Styling (bg-, border-, etc.)
  6. Interactive States (hover:, focus:, etc.)
  7. Responsive Variants (sm:, md:, etc.)

Here's a practical example of well-organized button classes:

<button
  class="
  /<em> Layout </em>/
  flex items-center justify-center
  /<em> Box Model </em>/
  w-full max-w-xs px-4 py-2 m-2
  /<em> Typography </em>/
  font-semibold text-sm text-white
  /<em> Visual </em>/
  bg-blue-600 rounded-lg shadow-md
  /<em> Interactive </em>/
  hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500
  /<em> Responsive </em>/
  sm:w-auto md:text-base
"
<blockquote class="pl-4 border-l-4 border-gray-300 italic">Submit</blockquote>
</button>
Using Comments for Organization

For complex components, adding comments to group related classes improves readability:

<div
  class="
  /<em> Layout </em>/
  grid grid-cols-1 gap-4
  /<em> Responsive </em>/
  sm:grid-cols-2 md:grid-cols-3
"
<blockquote class="pl-4 border-l-4 border-gray-300 italic"><!-- Content --></blockquote>
</div>
Linting and Formatting Tools Official Tailwind CSS Linter

In 2025, the official Tailwind CSS linter has become essential for maintaining class order consistency:

npm install --save-dev @tailwindcss/stylelint-plugin

Configuration in .stylelintrc.js:

module.exports = {
  extends: ['stylelint-config-standard'],
  plugins: ['@tailwindcss/stylelint-plugin'],
  rules: {
    '@tailwindcss/class-order': [
      true,
      {
        order: [
          'layout',
          'position',
          'display',
          'boxModel',
          'typography',
          'visual',
          'interactive',
          'responsive',
        ],
      },
    ],
    '@tailwindcss/no-contradicting-classes': true,
    '@tailwindcss/no-unnecessary-variants': true,
  },
};
ESLint Plugin for Tailwind

The ESLint plugin for Tailwind CSS helps enforce best practices in your JSX/TSX files:

npm install --save-dev eslint-plugin-tailwindcss

Configuration in .eslintrc.js:

module.exports = {
  plugins: ['tailwindcss'],
  extends: ['plugin:tailwindcss/recommended'],
  rules: {
    'tailwindcss/classnames-order': 'error',
    'tailwindcss/no-custom-classname': 'warn',
    'tailwindcss/no-contradicting-classname': 'error',
  },
};
VS Code Extensions

Essential VS Code extensions for Tailwind development in 2025:

  1. Tailwind CSS IntelliSense - Offers advanced class suggestions and linting
  2. Headwind - Enforces consistent class ordering
  3. Tailwind Fold - Collapses Tailwind classes for better readability

Practical Examples#

Card Component with Organized Classes
function ProductCard({ product }) {
  return (
    <div
      className="
      /<em> Layout </em>/
      flex flex-col
      /<em> Box Model </em>/
      w-full max-w-sm p-4 mx-auto
      /<em> Visual </em>/
      bg-white rounded-xl shadow-lg
      /<em> Interactive </em>/
      hover:shadow-xl
      /<em> Responsive </em>/
      sm:flex-row sm:p-6
    "
    >
      <img
        src={product.image}
        alt={product.name}
        className="
          /<em> Box Model </em>/
          w-full h-48 mb-4
          /<em> Visual </em>/
          object-cover rounded-lg
          /<em> Responsive </em>/
          sm:w-1/3 sm:h-auto sm:mb-0 sm:mr-4
        "
      />
      <div
        className="
        /<em> Layout </em>/
        flex flex-col
        /<em> Box Model </em>/
        flex-grow
      "
      >
        <h2 className="text-xl font-bold text-gray-900">{product.name}</h2>
        <p className="mt-2 text-gray-600">{product.description}</p>
        <div
          className="
          /<em> Layout </em>/
          flex items-center justify-between
          /<em> Box Model </em>/
          mt-4
        "
        >
          <span className="text-lg font-bold text-blue-600">
            ${product.price}
          </span>
          <button
            className="
            /<em> Box Model </em>/
            px-4 py-2
            /<em> Typography </em>/
            font-medium text-white
            /<em> Visual </em>/
            bg-blue-600 rounded-lg
            /<em> Interactive </em>/
            hover:bg-blue-700 focus:outline-none focus:ring-2
          "
          >
            Add to Cart
          </button>
        </div>
      </div>
    </div>
  );
}
Navigation Bar Example
function Navbar() {
  return (
    <nav
      className="
      /<em> Layout </em>/
      flex items-center justify-between
      /<em> Box Model </em>/
      w-full px-4 py-3
      /<em> Visual </em>/
      bg-white shadow-md
      /<em> Responsive </em>/
      sm:px-6 md:px-8
    "
    >
      <div className="flex items-center">
        <img src="/logo.svg" alt="Logo" className="w-8 h-8 mr-2" />
        <span className="text-xl font-bold text-gray-900">Company</span>
      </div>

      <div
        className="
        /<em> Layout </em>/
        hidden
        /<em> Responsive </em>/
        md:flex md:items-center md:space-x-4
      "
      >
        <a
          href="/"
          className="
          /<em> Typography </em>/
          font-medium text-gray-700
          /<em> Interactive </em>/
          hover:text-blue-600
        "
        >
          Home
        </a>
        <a
          href="/products"
          className="
          /<em> Typography </em>/
          font-medium text-gray-700
          /<em> Interactive </em>/
          hover:text-blue-600
        "
        >
          Products
        </a>
        <a
          href="/about"
          className="
          /<em> Typography </em>/
          font-medium text-gray-700
          /<em> Interactive </em>/
          hover:text-blue-600
        "
        >
          About
        </a>
        <a
          href="/contact"
          className="
          /<em> Typography </em>/
          font-medium text-gray-700
          /<em> Interactive </em>/
          hover:text-blue-600
        "
        >
          Contact
        </a>
      </div>

      <button
        className="
        /<em> Layout </em>/
        flex items-center
        /<em> Box Model </em>/
        p-2
        /<em> Visual </em>/
        rounded-md
        /<em> Interactive </em>/
        hover:bg-gray-100
        /<em> Responsive </em>/
        md:hidden
      "
        aria-label="Toggle menu"
      >
        <svg
          className="w-6 h-6"
          fill="none"
          stroke="currentColor"
          viewBox="0 0 24 24"
        >
          <path
            strokeLinecap="round"
            strokeLinejoin="round"
            strokeWidth="2"
            d="M4 6h16M4 12h16M4 18h16"
          />
        </svg>
      </button>
    </nav>
  );
}

Automated Class Sorting with Prettier#

Prettier now offers a Tailwind CSS plugin that automatically sorts classes according to recommended conventions:

npm install --save-dev prettier prettier-plugin-tailwindcss

Configuration in prettier.config.js:

module.exports = {
  plugins: [require('prettier-plugin-tailwindcss')],
  tailwindConfig: './tailwind.config.js',
  tailwindFunctions: ['clsx', 'cn', 'cva'],
};

Best Practices for Large Projects#

Extract Component Classes with @apply

For complex, reusable components, use @apply in your CSS:

/<em > components.css </em > / @layer components {
  .card {
    @apply flex flex-col w-full max-w-sm p-4 mx-auto bg-white rounded-xl shadow-lg hover:shadow-xl sm:flex-row sm:p-6;
  }

  .card-image {
    @apply w-full h-48 mb-4 object-cover rounded-lg sm:w-1/3 sm:h-auto sm:mb-0 sm:mr-4;
  }

  .card-content {
    @apply flex flex-col flex-grow;
  }

  .btn-primary {
    @apply px-4 py-2 font-medium text-white bg-blue-600 rounded-lg hover:bg-blue-700 focus:outline-none focus:ring-2;
  }
}
Use Composition for Complex UI

Break down complex UI into smaller components with focused class sets:

function ProfileCard({ user }) {
  return (
    <Card>
      <CardHeader>
        <Avatar src={user.avatar} alt={user.name} />
        <UserName>{user.name}</UserName>
      </CardHeader>
      <CardBody>
        <UserBio>{user.bio}</UserBio>
        <UserStats followers={user.followers} following={user.following} />
      </CardBody>
      <CardFooter>
        <FollowButton userId={user.id} />
        <MessageButton userId={user.id} />
      </CardFooter>
    </Card>
  );
}

// Each component has its own focused set of Tailwind classes
function Card({ children }) {
  return (
    <div
      className="
      flex flex-col
      w-full max-w-md p-6
      bg-white rounded-xl shadow-lg
    "
    >
      {children}
    </div>
  );
}

function CardHeader({ children }) {
  return (
    <div
      className="
      flex items-center
      mb-4 pb-4
      border-b border-gray-100
    "
    >
      {children}
    </div>
  );
}

// And so on for other components...

Conclusion#

Consistent class organization is no longer optional for Tailwind CSS projects in 2025. By following these ordering conventions and leveraging modern linting tools, you can maintain readable, maintainable code even as your projects scale. The examples provided demonstrate how proper class organization improves code quality and developer experience across different component types.

Share this post

Previous Article

Tailwind CSS - A Beginner Guide

Next Article

Server Components vs Client Components i...

You might also like

Tailwind CSS - A Beginner Guide

Tailwind CSS - A Beginner Guide

March 11, 2025

Color psychology

Color psychology

February 9, 2020

Learning to Code Was Never the Point. Learning Software Was.

Learning to Code Was Never the Point. Learning Software Was.

July 23, 2026

Loading table of contents...

Recent Posts

  • Learning to Code Was Never the Point. Learning Software Was.
    July 23, 2026
  • Git Conflicts in VS Code: A Beginner-Friendly Guide
    March 20, 2025
  • Trunk-Based Development: A Guide for Beginners
    March 19, 2025
  • GraphQL and Next.js: Filtering, Searching, and Sorting
    March 18, 2025
  • Understanding GraphQL in 2025: A Comprehensive Guide
    March 17, 2025