๐Ÿ”ฅ All-Access Pass โ€” $199 USD (Regular $499) ยท Unlock all 2,836 Astro themes โž”
komal.nakrani
Get All-Access Pass ($199)
ThemesCategoriesDocsBlogTips & TricksPricingGet All-Access Pass ($199)
Stylingโ€ขโ€ขBy Komal Nakrani

Astro UnoCSS Setup: Atomic CSS With the Official Integration

Add Astro UnoCSS in three steps: install unocss, register the unocss/astro integration, and write a uno.config.ts. Presets, shortcuts, icons and Tailwind compared.

#Astro#UnoCSS#Atomic CSS#Styling

To use Astro UnoCSS, install unocss, add the UnoCSS() integration from unocss/astro to astro.config.mjs, and create a uno.config.ts with the presets you want. UnoCSS then scans your .astro, Markdown and framework files and generates only the utility classes you use, with Tailwind-compatible class names if you pick the Wind preset.

Key Takeaways

  • UnoCSS ships its own Astro integration, unocss/astro.
  • The integration injects the generated CSS for you; set injectReset: true to add a CSS reset too.
  • presetWind3 gives Tailwind-style utilities; shortcuts and the icons preset are where UnoCSS differs most.
  • Choose UnoCSS for its flexibility and icons; choose Tailwind for the larger ecosystem.

Install and register

npm install -D unocss
// astro.config.mjs
import { defineConfig } from 'astro/config';
import UnoCSS from 'unocss/astro';

export default defineConfig({
  integrations: [UnoCSS({ injectReset: true })],
});

With injectReset: true, the integration adds a Tailwind-style reset before the generated utilities, so headings and lists start unstyled in the same way. Leave it out if you bring your own reset.

Configure presets and shortcuts

// uno.config.ts
import { defineConfig, presetWind3, presetIcons } from 'unocss';

export default defineConfig({
  presets: [presetWind3(), presetIcons()],
  theme: {
    colors: {
      brand: { DEFAULT: '#0f766e', dark: '#115e59' },
    },
  },
  shortcuts: {
    btn: 'inline-flex items-center gap-2 rounded-lg px-4 py-2 font-medium',
    'btn-primary': 'btn bg-brand text-white hover:bg-brand-dark',
  },
});

Shortcuts turn a group of utilities into one class without a CSS file, which keeps component markup short:

---
// src/components/Cta.astro
---
<a href="/themes/" class="btn-primary">
  <span class="i-lucide-arrow-right" aria-hidden="true"></span>
  Browse themes
</a>

The i-lucide-arrow-right class comes from the icons preset. It renders a pure CSS icon from the Iconify set, with no JavaScript and no SVG in the markup. Install the icon collection you use, for example npm install -D @iconify-json/lucide.

UnoCSS or Tailwind in Astro

UnoCSS Tailwind CSS 4
Astro setup unocss/astro integration @tailwindcss/vite plugin
Config uno.config.ts (TypeScript) @theme in CSS
Class names Tailwind-compatible via preset, or your own rules Tailwind only
Icons Built-in CSS icons preset Separate package
Ecosystem Smaller Larger: UI kits, themes, docs, answers

Pick UnoCSS if you want custom rules, attributify mode or CSS icons out of the box. Pick Tailwind if you want the largest set of examples, themes and plugins, which is why most Astro themes, ours included, use it. Our CSS frameworks for Astro guide compares more options, and Tailwind CSS v4 in Astro covers the alternative setup.

Troubleshooting

  • Classes missing in production. Classes built from strings at runtime cannot be detected. Write full class names, or add them to safelist in the config.
  • Styles appear twice. Remove any manual import 'uno.css'; the integration injects the CSS already.
  • Icons do not render. The @iconify-json/<set> package for that icon set is not installed.

The UnoCSS Astro integration docs list every option. Most of our Astro themes use Tailwind CSS, and the theme styling docs explain how to swap utility frameworks.

FAQ

Does UnoCSS work with Astro?

Yes. UnoCSS ships an official Astro integration, unocss/astro, that scans your components and injects the generated CSS into every page.

Can I use Tailwind class names with UnoCSS in Astro?

Yes. The Wind preset implements Tailwind-style utilities, so most Tailwind class names work. Some newer Tailwind 4 utilities and plugins may not have an equivalent.

Is UnoCSS faster than Tailwind in Astro?

Both generate only the classes you use, so the CSS sent to browsers is small either way. Build speed differences are rarely noticeable on a typical Astro site.