<!--
Sitemap:
- [What is Vocs](/guide/what-is-vocs): Learn what Vocs provides for documentation sites
- [Getting Started](/guide/getting-started): Install Vocs and create your first documentation site
- [Writing Docs with AI](/guide/writing-docs-with-ai): Use an AI agent to create and maintain Vocs documentation
- [Project Structure](/guide/structure): Overview of the structure of a Vocs project
- [Markdown Extensions](/guide/markdown-extensions): Features and syntax of Markdown in Vocs
- [Code & Syntax Highlighting](/guide/syntax-highlighting): Rich markup and annotations for code
- [Code Snippets](/guide/code-snippets): Include and reuse code in Markdown
- [Markdown Snippets](/guide/markdown-snippets): Include other Markdown files in MDX
- [Asset Handling](/guide/asset-handling): Manage images, fonts, icons, and other docs assets
- [Frontmatter](/guide/frontmatter): Configure page metadata, layouts, search, and UI visibility
- [Using React in Markdown](/guide/react): Compose MDX pages with React components
- [Twoslash](/guide/twoslash): Add type-aware annotations to code examples
- [Sidebar & Top Navigation](/guide/navigation): Keep docs navigation synced with routes
- [Theming](/guide/theming): Customize colors, typography, spacing, logos, and code themes
- [Tailwind CSS](/guide/tailwind): Use Tailwind utilities in Vocs pages and components
- [Layouts](/guide/layouts): Choose and customize page shells for your docs
- [Dynamic OG Images](/guide/dynamic-og-images): Generate social preview images from page metadata
- [Feedback](/guide/feedback): Collect page-level feedback from readers
- [Changelog Generation](/guide/changelog-generation): Fetch release notes and render a changelog page
- [MCP Server](/guide/mcp-server): Expose your docs and source code to AI assistants
- [AI Support](/guide/ai-support): Make your documentation easier for AI assistants to read
- [Site Configuration](/reference/site-config): Reference for options accepted by defineConfig
- [Components](/reference/components): Reference for the public React components exported from Vocs
- [Hooks](/reference/hooks): Reference for the React hooks exported from Vocs
- [Changelog](/guide/changelog): Release history for Vocs
-->

# Tailwind CSS \[Use Tailwind utilities in Vocs pages and components]

Vocs includes Tailwind's Vite plugin in its default Vite stack. Add Tailwind to your project, import it from `src/pages/_root.css`, then use utilities in MDX and React components.

You do not need to install `@tailwindcss/vite` or edit `vite.config.ts` just to enable Tailwind.

## Quick Prompt

Ask your AI agent to wire Tailwind into your Vocs project:

```txt
Read https://vocs.dev/guide/tailwind and add Tailwind CSS to my Vocs project.
```

## Install Tailwind

Add `tailwindcss` to your project.

:::code-group

```bash [npm]
npm install -D tailwindcss
```

```bash [pnpm]
pnpm add -D tailwindcss
```

```bash [yarn]
yarn add -D tailwindcss
```

```bash [bun]
bun add -D tailwindcss
```

:::

## Import Tailwind

Create `src/pages/_root.css`, then import Tailwind from there. Vocs loads this file automatically on every page.

:::file-tree

* +src
  * +pages
    * \_root.css Global styles.
      :::

```css [src/pages/_root.css]
@import 'tailwindcss';
```

Tailwind automatically scans your Vocs pages and components, so most projects do not need a Tailwind config file.

## Use Utilities

Use Tailwind classes in JSX inside `.mdx` pages and React components.

```mdx [src/pages/index.mdx]
# Docs

<div className="rounded-lg border border-zinc-200 p-4 dark:border-zinc-800">
  <h2 className="m-0 text-2xl font-semibold">Deploy Contracts</h2>
  <p className="m-0 text-zinc-600 dark:text-zinc-400">
    Ship Solidity apps with Vite-native docs.
  </p>
</div>
```

Use `className` inside JSX. Plain Markdown syntax does not accept Tailwind classes directly, so switch to JSX when a block needs custom utility styling.

## Support Dark Mode

Vocs stores the active theme on the document's `color-scheme`. If you use Tailwind's `dark:` variant and want it to follow the Vocs theme toggle, add a custom dark variant in `_root.css`.

```css [src/pages/_root.css]
@import 'tailwindcss';

@custom-variant dark (&:where(:root[style*='color-scheme:dark'] *, :root[style*='color-scheme: dark'] *));
```

This lets classes like `dark:border-zinc-800` respond to the same theme state as the built-in Vocs UI.

## Reuse Vocs Tokens

Map Vocs CSS variables into Tailwind theme tokens when custom components should follow the docs theme.

```css [src/pages/_root.css]
@import 'tailwindcss';

@theme {
  --color-vocs-accent: var(--vocs-color-accent);
  --font-sans: var(--vocs-font-family);
  --font-mono: var(--vocs-font-family-mono);
}
```

```mdx [src/pages/index.mdx]
<a className="font-sans text-vocs-accent" href="/guide/getting-started">
  Start building
</a>
```

## Skip Preflight

`@import 'tailwindcss'` enables Tailwind's full default CSS, including Preflight. If you only want Tailwind theme tokens and utilities, import those layers instead.

```css [src/pages/_root.css]
@import 'tailwindcss/theme.css' layer(theme);
@import 'tailwindcss/utilities.css' layer(utilities);
```

Start with the full import unless you have a specific reason to avoid Tailwind's base styles.

See also: [Theming](/guide/theming)
