SVG Icons with Tailwind CSS – currentColor, Dark Mode & Best Libraries

How to use SVG icons with Tailwind CSS. Covers currentColor, dark mode, sizing with h-* w-* classes, and which icon libraries work best with Tailwind.

Amit Yadav
Amit Yadav

Tailwind CSS and SVG icons pair naturally through currentColor — your icon inherits any text color class you apply. Here’s how to get clean, scalable icons with Tailwind.

Best icon libraries for Tailwind CSS

Heroicons is built by the Tailwind team and uses the exact same sizing scale. Lucide is the second most popular choice for Tailwind projects.

Color via currentColor

Stroked SVG icons (Lucide, Heroicons, Tabler) use currentColor by default, so they inherit Tailwind text color classes:

<!-- Tailwind text color classes control the icon color -->
<svg class="h-5 w-5 text-indigo-600" ...>...</svg>

<!-- Dark mode variant -->
<svg class="h-5 w-5 text-gray-800 dark:text-gray-200" ...>...</svg>

<!-- Hover color -->
<svg class="h-5 w-5 text-gray-500 hover:text-gray-900 transition-colors" ...>...</svg>

Sizing with h-* and w-* classes

Tailwind’s spacing scale maps directly to icon sizes:

Tailwind classSize
h-4 w-416px
h-5 w-520px
h-6 w-624px
h-8 w-832px
h-10 w-1040px
<svg class="h-5 w-5" ...>...</svg>    <!-- inline, 20px -->
<svg class="h-6 w-6" ...>...</svg>    <!-- standard, 24px -->

Heroicons with Tailwind

Heroicons was designed for Tailwind — it ships two variant sets matching Tailwind’s design language:

import {
  HomeIcon,           // outline variant (24px)
  BellIcon,
  Cog6ToothIcon,
} from '@heroicons/react/24/outline';

import {
  HomeIcon as HomeSolid,  // solid variant
} from '@heroicons/react/24/solid';

// 20px mini variant (matches Tailwind's text-sm ui density)
import { HomeIcon as HomeMini } from '@heroicons/react/20/solid';

export function Nav() {
  return (
    <nav className="flex items-center gap-3">
      <HomeIcon className="h-5 w-5 text-gray-600" />
      <BellIcon className="h-5 w-5 text-gray-600 hover:text-indigo-600 transition" />
    </nav>
  );
}

Lucide React with Tailwind

import { Home, Bell, Settings } from 'lucide-react';

// Use className for color, size prop or h-/w- classes for size
<Home className="h-5 w-5 text-gray-700 dark:text-gray-300" />

// strokeWidth for thinner or bolder strokes
<Home className="h-5 w-5" strokeWidth={1.5} />
<Home className="h-5 w-5" strokeWidth={2.5} />

Dark mode icons

Tip

Use Tailwind’s dark: prefix on text-* classes — the icon color follows automatically because SVG uses currentColor.

<!-- Light: gray-700, Dark: gray-300 -->
<svg class="h-5 w-5 text-gray-700 dark:text-gray-300" ...>...</svg>

<!-- Light: indigo-600, Dark: indigo-400 -->
<svg class="h-5 w-5 text-indigo-600 dark:text-indigo-400" ...>...</svg>

Filled icons vs stroked icons

Filled icons (like Heroicons solid) use fill="currentColor" — not stroke. The rules are the same: control color via Tailwind text-* classes.

<!-- Stroked icon -->
<svg stroke="currentColor" fill="none" class="h-5 w-5 text-gray-600" ...>...</svg>

<!-- Filled icon -->
<svg fill="currentColor" stroke="none" class="h-5 w-5 text-indigo-600" ...>...</svg>

Icon button with Tailwind

<button
  className="inline-flex items-center justify-center h-9 w-9 rounded-md
    text-gray-500 hover:bg-gray-100 hover:text-gray-900
    dark:hover:bg-gray-800 dark:hover:text-gray-100
    transition-colors"
  aria-label="Settings"
>
  <Settings className="h-4 w-4" aria-hidden="true" />
</button>

Tailwind plugin: @tailwindcss/forms icons

The Tailwind forms plugin uses background-image SVG for checkboxes and radios — those are different from component icons. For UI component icons, use an icon library component, not a background image.

Inline SVG approach (no package)

Copy from AllSVGIcons and paste directly — add Tailwind classes on the <svg> element:

<svg
  xmlns="http://www.w3.org/2000/svg"
  class="h-5 w-5 text-gray-600 hover:text-indigo-600 transition-colors"
  fill="none"
  viewBox="0 0 24 24"
  stroke="currentColor"
  stroke-width="2"
  aria-hidden="true"
>
  <path stroke-linecap="round" stroke-linejoin="round"
    d="M21 21l-4.35-4.35M17 11A6 6 0 1 1 5 11a6 6 0 0 1 12 0z" />
</svg>

Frequently asked questions

Use Tailwind text color classes like text-gray-600 or text-indigo-500 on the SVG element. Most icon libraries (Lucide, Heroicons, Tabler) use currentColor for stroke or fill, so they inherit text color automatically.

Heroicons was made by the Tailwind team and fits perfectly. Lucide React is the most popular overall and also works great with Tailwind. Both use currentColor and support dark mode via Tailwind's dark: prefix.

Use Tailwind's responsive prefixes: sm:h-4 sm:w-4 md:h-5 md:w-5 lg:h-6 lg:w-6. This scales icons at different breakpoints without writing custom CSS.

Use h-* w-* utility classes: h-4 w-4 for 16px, h-5 w-5 for 20px, h-6 w-6 for 24px. You can also use the size prop on React icon components (size={20}) alongside a className.

Yes. Since icons inherit text color via currentColor, dark mode is as simple as adding a dark: variant: class='text-gray-700 dark:text-gray-300'. No special icon setup needed.
Share this post