> ## Documentation Index
> Fetch the complete documentation index at: https://extension.js.org/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Extension.js needs Node.js 22.12 or newer; Node.js 18 and 20 do not work. It also runs on Deno 2.5+ and Bun 1.2+.
> The default browser target is chromium and a build lands in dist/<browser>, so dist/chromium by default. extension build writes a zip only when --zip is passed.
> Prefix a manifest key with a browser name when browsers differ. chromium: covers every Chromium-family target and Safari builds read it too. Since 4.1.19 chrome: means Chrome alone and edge: means Edge alone.
> Write one background.service_worker in manifest.json instead of hand-writing per-browser background keys; Extension.js converts it for each browser.
> package.json or deno.json marks the project root, not manifest.json. A config file is optional, and only extension.config.js, .mjs and .cjs are loaded, never .ts.
> The bundler is Rspack, extended through the config hook in extension.config.js. A project needs no separate bundler config file.
> Use --no-browser to skip the browser launch; --no-runner no longer exists and --no-open still launches the browser. Use --output for machine output; --format and --wait-format are deprecated.

# Tailwind CSS in browser extensions

> Style browser extension popups, options pages, sidebars, and content scripts with Tailwind CSS utility classes. Supports Tailwind v3 and v4 via PostCSS.

Build extension UI surfaces quickly with utility classes across popup, options, new tab, sidebar, and content-script entries.

Extension.js integrates Tailwind through PostCSS and supports both Tailwind v3 and v4 setups.

## When Tailwind CSS is a good fit

* You need fast UI iteration across multiple extension surfaces.
* You prefer utility-first styling with shared tokens.
* You want consistent styling patterns across page and content-script entries.

## Tailwind capabilities

| Capability | What it gives you |
| - | - |
| Multi-surface styling | Reuse utility classes across extension pages and content scripts |
| PostCSS-based integration | Keep Tailwind in the same CSS transform pipeline as the rest of your project |
| Version flexibility | Support Tailwind v3 and Tailwind v4 plugin patterns |
| Template onboarding | Start from ready-made setups and adapt incrementally |

## Template examples

### Sidebar + Tailwind + shadcn/ui

Use this template when you want a complete Tailwind setup in a real extension UI surface.

![sidebar-shadcn screenshot](https://mintcdn.com/extensionjs/VCnDd7fX2Nza24SE/images/examples/sidebar-shadcn/screenshot.png?fit=max\&auto=format\&n=VCnDd7fX2Nza24SE\&q=85\&s=33a9282aa769b690de933e901aeee333)

```bash npm theme={null}
npx extension@latest create my-extension --template=sidebar-shadcn
```

```bash pnpm theme={null}
pnpx extension@latest create my-extension --template=sidebar-shadcn
```

```bash yarn 2+ theme={null}
yarn dlx extension@latest create my-extension --template=sidebar-shadcn
```

```bash bun theme={null}
bunx extension@latest create my-extension --template=sidebar-shadcn
```

```bash deno theme={null}
deno run -A npm:extension@latest create my-extension --template=sidebar-shadcn
```

Repository: [examples/sidebar-shadcn](https://github.com/extension-js/templates/tree/main/examples/sidebar-shadcn)

## Usage with an existing extension

### Installation

Install the required dependencies:

```bash npm theme={null}
npm install -D tailwindcss @tailwindcss/postcss postcss
```

```bash pnpm theme={null}
pnpm install -D tailwindcss @tailwindcss/postcss postcss
```

```bash yarn theme={null}
yarn add -D tailwindcss @tailwindcss/postcss postcss
```

```bash bun theme={null}
bun add --dev tailwindcss @tailwindcss/postcss postcss
```

```bash deno theme={null}
deno add npm:tailwindcss npm:@tailwindcss/postcss npm:postcss
```

### Configuration

Create `postcss.config.js`:

```js theme={null}
export default {
  plugins: {
    "@tailwindcss/postcss": {},
  },
};
```

For Tailwind v3 projects, use `tailwindcss` as the PostCSS plugin and keep a `tailwind.config.js` content list.

### Tailwind v4 vs v3 quick setup

```js theme={null}
// Tailwind v4 postcss.config.js
export default {
  plugins: {
    "@tailwindcss/postcss": {},
  },
};
```

```js theme={null}
// Tailwind v3 postcss.config.js
export default {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  },
};
```

### Tailwind content paths (v3 style)

```js theme={null}
/** @type {import('tailwindcss').Config} */
export default {
  content: [
    "./pages/**/*.{html,js,ts,jsx,tsx,mdx}",
    "./scripts/**/*.{js,ts,jsx,tsx}",
    "./src/**/*.{html,js,ts,jsx,tsx,mdx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
};
```

### Usage

Create a global stylesheet and import Tailwind:

#### Create the global CSS file

```css theme={null}
/* styles/globals.css */
@import "tailwindcss";
```

Import this file in entry scripts that use Tailwind classes.

#### In a page script (popup/options/new-tab)

```tsx theme={null}
import "./styles/globals.css";

export default function MyNewTabPage() {
  return <h1 className="text-4xl font-bold">Hello, Extension.</h1>;
}
```

#### In a content script

```ts theme={null}
export default function initial() {
  const rootDiv = document.createElement("div");
  rootDiv.setAttribute("data-extension-root", "true");
  rootDiv.style.cssText = "all: initial !important";
  document.body.appendChild(rootDiv);

  const shadowRoot = rootDiv.attachShadow({ mode: "open" });
  const styleElement = document.createElement("style");
  shadowRoot.appendChild(styleElement);

  fetchCSS().then((css) => (styleElement.textContent = css));

  const badge = document.createElement("div");
  badge.className = "fixed bottom-0 right-0 p-4 text-sm font-bold";
  badge.textContent = "Hello, Extension.";
  shadowRoot.appendChild(badge);

  return () => rootDiv.remove();
}

async function fetchCSS() {
  const cssUrl = new URL("./styles/globals.css", import.meta.url);
  const response = await fetch(cssUrl);
  const text = await response.text();
  return response.ok ? text : Promise.reject(text);
}
```

Tailwind compiles the stylesheet at build time, and the script loads it into the shadow root. A plain `import "./styles/globals.css"` styles nothing in a content script. See [CSS, Sass, and Less](https://extension.js.org/docs/implementation-guide/css.md) for every route.

[Extension.js: Tailwind CSS HMR](https://www.youtube-nocookie.com/embed/XzWYAsOfYgE?rel=0)

### Body fonts on extension pages

Chrome adds its own stylesheet to extension pages. That stylesheet sets the `body` font family to `system-ui, sans-serif` and the font size to 75%, and it is not in a cascade layer. Styles outside a layer beat layered styles, so a font that you set only in `@layer base` does not reach `body` or the elements inside it.

Set the body font in a rule outside any layer:

```css theme={null}
@import "tailwindcss";

:root body {
  font-family: "Inter", sans-serif;
}
```

The `:root` prefix makes the rule win in whatever order the stylesheets load. Keep your other base styles in `@layer base`.

## Best practices

* Keep Tailwind source imports in shared style entry files (`styles/globals.css`).
* Ensure your content scanning includes `pages/`, `scripts/`, and `src/` when relevant.
* In monorepos, verify Tailwind content paths resolve from the extension project root.
* Use templates when possible to avoid configuration drift between PostCSS and Tailwind versions.

## Next steps

* Configure [PostCSS](https://extension.js.org/docs/integrations/postcss.md) for additional CSS transforms.
* Ensure your CSS follows best practices with [Stylelint](https://extension.js.org/docs/integrations/stylelint.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.