Do
- Design mobile-first: base classes for phones, then
sm:,md:,lg: - Stick to the scale (
p-4,text-lg) for a consistent design; use arbitrary values rarely - Define your brand in
@themeinstead of repeating hex codes - Use components (Blade, React) for repeated UI
- Sort classes automatically with
prettier-plugin-tailwindcss - Install Tailwind CSS IntelliSense in VS Code for autocomplete and previews
- Keep accessibility in mind:
focus-visible:styles,sr-onlytext for icon buttons, good colour contrast - Use a build step (Vite or CLI) in production, not the Play CDN
Avoid
- Building class names with string joining:
'text-' + color + '-500'(Tailwind cannot detect it) - Using conflicting classes on one element:
p-2 p-4 - Fighting Tailwind with lots of custom CSS and
!important - Forgetting colours on borders in v4 (
border border-gray-200)
Tailwind in Laravel
New Laravel apps include Tailwind with Vite. Write classes in Blade files, run npm run dev while developing and npm run build before deploying.
Example
Example — Accessible, consistent component
HTML
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
<main class="max-w-md mx-auto p-6">
<article class="rounded-2xl border border-slate-200 bg-white p-5 shadow-sm">
<header class="flex items-center justify-between">
<h2 class="text-lg font-semibold text-slate-900">Tailwind CSS Tutorial</h2>
<button class="rounded-full p-2 text-slate-500 hover:bg-slate-100 hover:text-rose-600 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600">
<span class="sr-only">Add to favourites</span>
<svg class="size-5" fill="currentColor" viewBox="0 0 20 20" aria-hidden="true"><path d="M10 17l-1.45-1.32C4.4 12.36 2 10.28 2 7.5 2 5.42 3.42 4 5.5 4c1.24 0 2.41.58 3.17 1.5h2.66C12.09 4.58 13.26 4 14.5 4 16.58 4 18 5.42 18 7.5c0 2.78-2.4 4.86-6.55 8.18L10 17z"/></svg>
</button>
</header>
<p class="mt-2 text-sm text-slate-600">27 lessons · Beginner friendly</p>
<a href="#" class="mt-4 block rounded-lg bg-indigo-600 py-2 text-center font-semibold text-white hover:bg-indigo-700 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600">Start learning</a>
</article>
</main>
sr-only gives the icon button a name for screen readers, and every interactive element has a visible keyboard focus style.
Try it Now »