tailwindcss-obfuscator Svelte Themes

Tailwindcss Obfuscator

Tailwind CSS class obfuscation for Vite, Webpack, Rollup, esbuild, Next.js, Nuxt, SvelteKit, Astro, Remix / React Router 7, Solid, Qwik, Vue & TanStack Router โ€” supports Tailwind v3 + v4. Shrinks bundles, protects your design system.



Tailwind CSS Obfuscator



๐Ÿ›ก๏ธ Tailwind CSS Obfuscator
(a.k.a. Tailwind Class Mangler)

Mangle Tailwind classes. Shrink your bundles 30โ€“60%. Protect your design system.

The most complete Tailwind CSS class mangler / obfuscator on npm โ€”
built for Tailwind v3 & v4, every major framework, every build tool.
Both terms describe the same build-time transformation : rewrite verbose utilities (bg-blue-500) into short opaque ones (tw-a).


npm version npm install TypeScript types bundle size license

TypeScript Tailwind CSS Vite Webpack esbuild

GitHub stars GitHub forks GitHub issues last commit

OpenSSF Best Practices OpenSSF Scorecard CodeQL Code coverage npm provenance


  ๐Ÿš€ Quick Start       ๐Ÿ“– Docs       ๐Ÿ“ฆ Package       ๐Ÿ’ก Examples       ๐Ÿ› Report Bug  


[!IMPORTANT] ๐Ÿ”ฅ What if a single line in your vite.config.js could shrink your CSS by 30โ€“60% and make your design system uncopyable? That's exactly what tailwindcss-obfuscator does โ€” at build time, with zero runtime overhead.

๐Ÿ“– Documentation

๐Ÿ‘‰ josedacosta.github.io/tailwindcss-obfuscator ๐Ÿ‘ˆ

Setup guide for every framework ยท complete options reference ยท the patterns that obfuscate (and the ones that don't) ยท maintainers' checklist ยท comparison with tailwindcss-mangle.

๐ŸŒ Live docs site ๐Ÿ“‚ Docs source on GitHub
Hosted on GitHub Pages, rebuilt on every push to main Edit a page, open a PR

๐Ÿ“‘ Table of Contents

Get started

Deep dive

โœจ What is Class Obfuscation?

Class obfuscation (also called "class mangling") is a build-time transformation that replaces verbose Tailwind utility classes with short, opaque identifiers.

[!NOTE] ๐Ÿ’ก Build-time only โ€” your source code stays readable. Only the shipped HTML / CSS / JS bundles are obfuscated.

๐Ÿ”„ Before & After

๐Ÿ˜ฌ Before

<div class="flex min-h-screen items-center justify-center bg-gray-50">
  <button class="rounded bg-blue-500 px-4 py-2 text-white hover:bg-blue-600">Click me</button>
</div>

๐Ÿ“ 142 bytes

๐Ÿ˜Ž After

<div class="tw-a tw-b tw-c tw-d tw-e">
  <button class="tw-f tw-g tw-h tw-i tw-j tw-k">Click me</button>
</div>

๐Ÿ“ 86 bytes โšก โˆ’39%

๐ŸŽ What you gain

๐Ÿ”’

Design system
protection

Make your component patterns much harder to reverse-engineer

๐Ÿ“‰

Smaller
bundles

30โ€“60% reduction on CSS-heavy pages, even after Brotli/gzip

๐Ÿ•ต๏ธ

Hidden
internals

Hide which design tokens, breakpoints, plugins you use

โšก

Faster
parsing

Browser parses smaller selectors โ†’ shorter style recalc

๐ŸŽฏ Why this library?

There are a handful of class-mangling tools out there. Here's how this one stacks up against every active competitor โ€” tailwindcss-mangle, Obfustail, PostCSS minifiers, and Tailwind itself:

Capability ๐Ÿ›ก๏ธ tailwindcss-obfuscator ๐Ÿ”ง tailwindcss-mangle ๐ŸŒ Obfustail โš™๏ธ PostCSS minifiers (cssnano, csso) ๐Ÿ…’ Tailwind CSS itself
Tailwind v4 (CSS-first) support โœ… Native โœ… via CSS scan (v9) โœ… v4 only n/a โœ…
Tailwind v3 (config-file) support โœ… โœ… โŒ n/a โœ…
Renames classes (HTML / JS / CSS) โœ… โœ… โœ… โŒ โŒ
Doesn't modify your source files โœ… โœ… โŒ rewrites in place โœ… โœ…
Per-utility obfuscation (vs. per-string) โœ… โœ… โŒ per-full-string n/a n/a
Unified unplugin core (Vite/Webpack/Rollup/esbuild/Rspack/Farm) โœ… All six โš ๏ธ Vite + Webpack only โŒ build-time script โŒ โŒ
AST-based JSX/TSX transformer โœ… Babel โš ๏ธ Regex โŒ Regex n/a n/a
Vue SFC + Svelte class: directive โœ… โš ๏ธ Partial โŒ n/a n/a
cn() / clsx() / classnames() / twMerge() / cva() / tv() โœ… All six โš ๏ธ Two โŒ Manual safelist โŒ โŒ
Type-safe options + typed errors โœ… Strict TS โš ๏ธ Loose โŒ Pure JS n/a n/a
Source maps for transformed files โœ… โš ๏ธ โŒ โœ… โœ…
Reversible mapping file emitted โœ… โœ… โœ… โŒ โŒ
Standalone CLI (any project) โœ… tw-obfuscator โœ… tw-patch โŒ inline node script โœ… โœ…
Per-build randomization (no global state) โœ… โŒ โœ… n/a n/a
Tailwind config validator โœ… โŒ โŒ โŒ โŒ
Active framework coverage 20+ apps ~5 1 (Next.js) n/a n/a
Unquoted HTML attributes (class=foo, HTML5 spec) โœ… since v2.0.1 โŒ โŒ n/a n/a
Next.js Turbopack (post-build CLI workaround documented + tested) โœ… since v2.0.1 โŒ โš ๏ธ accidental (Next.js + Turbo) n/a n/a
npm publish with provenance (Sigstore / OIDC attestation) โœ… โŒ โŒ varies n/a
OpenSSF Scorecard published โœ… weekly โŒ โŒ n/a n/a
SBOM (SPDX-JSON) attached to every GitHub release โœ… โŒ โŒ n/a n/a

[!NOTE] ๐Ÿ“Š Want the methodology, version numbers, and per-tool deep-dive? See the full comparison page โ€” every cell above is sourced from the latest release of each project (April 2026).

โšก Performance impact

Real numbers measured on the included test apps (production builds, gzip):

App CSS size before CSS size after Reduction
test-vite-react (small dashboard) 24.1 KB 16.7 KB ๐ŸŸข โˆ’30.7%
test-shadcn-ui (CVA-heavy) 47.8 KB 28.4 KB ๐ŸŸข โˆ’40.6%
test-nextjs (marketing site) 68.9 KB 32.1 KB ๐ŸŸข โˆ’53.4%
test-nuxt (blog template) 41.2 KB 22.8 KB ๐ŸŸข โˆ’44.7%
test-static-html (landing page) 18.6 KB 8.9 KB ๐ŸŸข โˆ’52.2%

[!TIP] ๐Ÿ’ธ The bigger your CSS bundle, the bigger the savings. Apps that ship full Tailwind v3 with darkMode, safelist, and many variants tend to gain the most.

๐Ÿš€ Quick Start

๐Ÿ“ฆ Install

# pnpm (recommended)
pnpm add tailwindcss-obfuscator

# npm
npm install tailwindcss-obfuscator

# yarn
yarn add tailwindcss-obfuscator

# bun
bun add tailwindcss-obfuscator
โšก   Vite  (React, Vue, Svelte, Solid, Astro, Remix, Qwik)
// vite.config.js
import { defineConfig } from "vite";
import tailwindcss from "@tailwindcss/vite";
import { tailwindCssObfuscatorVite } from "tailwindcss-obfuscator/vite";

export default defineConfig({
  plugins: [
    tailwindcss(),
    tailwindCssObfuscatorVite({
      prefix: "tw-",
    }),
  ],
});
๐Ÿš€   Next.js  (Webpack)
// next.config.js
import { tailwindCssObfuscatorWebpack } from "tailwindcss-obfuscator/webpack";

const nextConfig = {
  webpack: (config, { dev }) => {
    if (!dev) {
      config.plugins.push(
        tailwindCssObfuscatorWebpack({
          prefix: "tw-",
        })
      );
    }
    return config;
  },
};

export default nextConfig;
๐ŸŸข   Nuxt 3
// nuxt.config.ts
export default defineNuxtConfig({
  modules: ["tailwindcss-obfuscator/nuxt"],
  tailwindcssObfuscator: {
    prefix: "tw-",
  },
});
๐Ÿ“ฆ   Rollup
// rollup.config.js
import { tailwindCssObfuscatorRollup } from "tailwindcss-obfuscator/rollup";

export default {
  plugins: [tailwindCssObfuscatorRollup({ prefix: "tw-" })],
};
โšก   esbuild
// build.js
import * as esbuild from "esbuild";
import { tailwindCssObfuscatorEsbuild } from "tailwindcss-obfuscator/esbuild";

await esbuild.build({
  entryPoints: ["src/index.ts"],
  bundle: true,
  outdir: "dist",
  plugins: [tailwindCssObfuscatorEsbuild({ prefix: "tw-" })],
});
๐Ÿ–ฅ๏ธ   CLI  (any build system)
# Extract + transform in one shot
npx tw-obfuscator run --build-dir dist

# Preview without writing files
npx tw-obfuscator run --dry-run

# Two-step workflow
npx tw-obfuscator extract
npx tw-obfuscator transform --dir dist

# Inspect a generated mapping
npx tw-obfuscator show --limit 50

[!TIP] ๐Ÿ“š See the package README for all options, framework recipes, and advanced customization (custom name generators, preserve.classes, validators...).

๐ŸŒ Supported Frameworks

Framework Version Plugin Status Test App
โš›๏ธ  React (Vite) 19 tailwindcss-obfuscator/vite ๐ŸŸข Tested apps/test-vite-react
โ–ฒ  Next.js 16 tailwindcss-obfuscator/webpack ๐ŸŸข Tested apps/test-nextjs
๐Ÿ’š  Vue (Vite) 3.5 tailwindcss-obfuscator/vite ๐ŸŸข Tested apps/test-vite-vue
๐ŸŸข  Nuxt 4 tailwindcss-obfuscator/nuxt ๐ŸŸข Tested apps/test-nuxt
๐Ÿ”ฅ  SvelteKit / Svelte 2.58 / 5 tailwindcss-obfuscator/vite ๐ŸŸข Tested apps/test-sveltekit
๐ŸŸฆ  Solid.js 1.9 tailwindcss-obfuscator/vite ๐ŸŸข Tested apps/test-solidjs
๐Ÿš€  Astro 6 tailwindcss-obfuscator/vite ๐ŸŸข Tested apps/test-astro
๐Ÿงญ  React Router (SSR) v7 tailwindcss-obfuscator/vite ๐ŸŸข Tested apps/test-react-router
๐Ÿชต  TanStack Router 1.168 tailwindcss-obfuscator/vite ๐ŸŸข Tested apps/test-tanstack-start
โšก  Qwik 1.19 tailwindcss-obfuscator/vite ๐ŸŸข Tested apps/test-qwik
๐ŸŽจ  shadcn/ui (CVA) latest tailwindcss-obfuscator/webpack ๐ŸŸข Tested apps/test-shadcn-ui
๐Ÿ“„  Static HTML โ€” tailwindcss-obfuscator/esbuild or CLI ๐ŸŸข Tested apps/test-static-html
๐Ÿงฐ  Webpack standalone 5.106 tailwindcss-obfuscator/webpack ๐ŸŸข Tested apps/test-webpack-standalone
๐Ÿ“ฆ  Rollup standalone 4.60 tailwindcss-obfuscator/rollup ๐ŸŸข Tested apps/test-rollup-standalone

๐Ÿ›๏ธ Architecture

The obfuscator runs in three phases. Every build tool plugin shares the same core pipeline thanks to a unified unplugin factory:

flowchart LR
    A[๐Ÿ“‚ Source files<br/>JSX, Vue, Svelte, HTML, CSS] -->|extract| B[๐Ÿ” Extractors<br/>regex + AST]
    B --> C[๐Ÿ—บ๏ธ Class Map<br/>Map&lt;original, obfuscated&gt;]
    C -->|transform| D[โœ๏ธ Transformers<br/>JSX-AST ยท PostCSS ยท HTML]
    D --> E[๐Ÿ“ฆ Output bundle<br/>obfuscated CSS, JS, HTML]
    C -.->|persist| F[๐Ÿ’พ .tw-obfuscation/<br/>class-mapping.json]

    style A fill:#1e293b,stroke:#38bdf8,color:#fff
    style B fill:#1e293b,stroke:#10b981,color:#fff
    style C fill:#1e293b,stroke:#eab308,color:#fff
    style D fill:#1e293b,stroke:#f97316,color:#fff
    style E fill:#1e293b,stroke:#8b5cf6,color:#fff
    style F fill:#1e293b,stroke:#64748b,color:#fff
๐Ÿงฉ   Internal module map
graph TB
    subgraph Plugins[" ๐Ÿ”Œ Build tool plugins "]
      Vite["vite.ts"]
      Webpack["webpack.ts"]
      Rollup["rollup.ts"]
      Esbuild["esbuild.ts"]
      Nuxt["nuxt.ts"]
    end

    subgraph Core[" โš™๏ธ unplugin core "]
      UnPlugin["plugins/core.ts<br/>(shared factory)"]
    end

    subgraph Pipeline[" ๐Ÿ”„ Pipeline "]
      Ctx["core/context.ts<br/>(state)"]
      Extract["extractors/*"]
      Transform["transformers/*"]
      Patterns["core/patterns/*<br/>(regex ยท variants ยท validators)"]
      Errors["core/errors.ts<br/>(typed exceptions)"]
    end

    Vite --> UnPlugin
    Webpack --> UnPlugin
    Rollup --> UnPlugin
    Esbuild --> UnPlugin
    Nuxt --> UnPlugin

    UnPlugin --> Ctx
    UnPlugin --> Extract
    UnPlugin --> Transform
    Extract --> Patterns
    Transform --> Patterns
    Ctx --> Errors

    style UnPlugin fill:#06b6d4,color:#fff
    style Patterns fill:#10b981,color:#fff
    style Ctx fill:#eab308,color:#000
    style Errors fill:#ef4444,color:#fff
๐Ÿ”   What gets extracted (per file type)
File type Extractor Captures
.html, .htm extractFromHtml class="..." attributes
.jsx, .tsx, .ts, .js extractFromJsx className="...", class="...", cn(), clsx(), cva(), tv(), twMerge()
.vue JSX extractor + Vue SFC support class, :class, object syntax, array syntax
.svelte JSX extractor + Svelte directive parser class, class:directive
.astro JSX extractor class, class:list
.css extractFromCss .classname selectors, escaped variants

๐Ÿ“‚ Project Structure

tailwindcss-obfuscator/
โ”‚
โ”œโ”€โ”€ ๐Ÿ“ฆ packages/
โ”‚   โ””โ”€โ”€ tailwindcss-obfuscator/      # ๐ŸŽฏ Main npm package (TypeScript)
โ”‚       โ”œโ”€โ”€ src/
โ”‚       โ”‚   โ”œโ”€โ”€ core/                # ๐Ÿง  Context, types, errors, patterns
โ”‚       โ”‚   โ”œโ”€โ”€ extractors/          # ๐Ÿ” HTML, JSX, Vue, Svelte, CSS scanners
โ”‚       โ”‚   โ”œโ”€โ”€ transformers/        # โœ๏ธ  CSS, HTML, JSX (regex + AST)
โ”‚       โ”‚   โ”œโ”€โ”€ plugins/             # ๐Ÿ”Œ unplugin core + bundler adapters
โ”‚       โ”‚   โ”œโ”€โ”€ cli/                 # ๐Ÿ–ฅ๏ธ  tw-obfuscator binary
โ”‚       โ”‚   โ””โ”€โ”€ utils/               # ๐Ÿ› ๏ธ  Logger
โ”‚       โ””โ”€โ”€ tests/                   # โœ… 360+ unit + benchmark tests
โ”‚
โ”œโ”€โ”€ ๐Ÿงช apps/                         # Integration test apps (17 frameworks)
โ”‚   โ”œโ”€โ”€ test-vite-react/             # โš›๏ธ  React 19 + Vite 8 + Tailwind v4
โ”‚   โ”œโ”€โ”€ test-vite-vue/               # ๐Ÿ’š Vue 3.5 + Vite 8 + Tailwind v4
โ”‚   โ”œโ”€โ”€ test-nextjs/                 # โ–ฒ  Next.js 16 + Tailwind v4 (webpack mode)
โ”‚   โ”œโ”€โ”€ test-nuxt/                   # ๐ŸŸข Nuxt 4 + Nitro + Tailwind v4
โ”‚   โ”œโ”€โ”€ test-sveltekit/              # ๐Ÿ”ฅ SvelteKit 2.58 + Svelte 5 + Tailwind v4
โ”‚   โ”œโ”€โ”€ test-astro/                  # ๐Ÿš€ Astro 6 + Tailwind v4
โ”‚   โ”œโ”€โ”€ test-solidjs/                # ๐ŸŸฆ Solid.js 1.9 + Vite 8 + Tailwind v4
โ”‚   โ”œโ”€โ”€ test-react-router/           # ๐Ÿงญ React Router v7 (ex-Remix) + Tailwind v4
โ”‚   โ”œโ”€โ”€ test-tanstack-start/         # ๐Ÿชต TanStack Router 1.168 + Tailwind v4
โ”‚   โ”œโ”€โ”€ test-qwik/                   # โšก Qwik 1.19 + Tailwind v4
โ”‚   โ”œโ”€โ”€ test-shadcn-ui/              # ๐ŸŽจ Next.js 16 + shadcn/ui + CVA
โ”‚   โ”œโ”€โ”€ test-static-html/            # ๐Ÿ“„ Static HTML + esbuild + Tailwind v4
โ”‚   โ”œโ”€โ”€ test-webpack-standalone/     # ๐Ÿงฐ Webpack 5 standalone (no meta-framework)
โ”‚   โ”œโ”€โ”€ test-rollup-standalone/      # ๐Ÿ“ฆ Rollup 4 standalone (no meta-framework)
โ”‚   โ”œโ”€โ”€ test-tailwind-v3/            # ๐ŸŽจ React + Vite + Tailwind v3
โ”‚   โ”œโ”€โ”€ test-tailwind-v4/            # ๐ŸŽจ React + Vite + Tailwind v4
โ”‚   โ”œโ”€โ”€ tailwind_v3_react_nextjs/    # ๐ŸŽจ Next.js + Tailwind v3 + shadcn (legacy)
โ”‚   โ””โ”€โ”€ tailwind_v4_react_nextjs/    # ๐ŸŽจ Next.js + Tailwind v4 + shadcn
โ”‚
โ”œโ”€โ”€ ๐Ÿ“š docs/                         # VitePress documentation
โ””โ”€โ”€ ๐Ÿ“‹ package.json                  # Root (TurboRepo + pnpm workspaces)

๐Ÿ› ๏ธ Development

๐Ÿ—๏ธ Setup

# 1. Install all monorepo dependencies
pnpm install

# 2. Build the main package
pnpm --filter tailwindcss-obfuscator build

# 3. Run the test suite (418 tests as of v2.1.0, growing)
pnpm --filter tailwindcss-obfuscator test

๐Ÿงฐ Common commands

Command Description
๐Ÿ”  pnpm dev Start every app in dev mode (via Turbo)
๐Ÿ—๏ธ  pnpm build Build every app with obfuscation enabled
โœ…  pnpm test Run the full test suite
๐Ÿ“Š  pnpm --filter tailwindcss-obfuscator bench Run performance benchmarks
๐Ÿšฆ  pnpm --filter tailwindcss-obfuscator test:integration Build every test app and verify obfuscation
๐Ÿ”  pnpm lint Lint with ESLint
๐Ÿ’…  pnpm format Format with Prettier

๐Ÿงช Per-app commands

# ๐ŸŽฏ Run a specific test app
pnpm --filter test-vite-react dev
pnpm --filter test-nextjs dev
pnpm --filter test-sveltekit dev

# ๐Ÿ—๏ธ Build a specific app
pnpm --filter test-vite-react build

๐ŸŽจ Tailwind CSS Version Support

๐Ÿ†• Tailwind v4 โ€” CSS-first

@import "tailwindcss";

@theme {
  --color-primary: #3b82f6;
  --font-display: "Inter", sans-serif;
}
  • โœ… Works with @tailwindcss/vite and @tailwindcss/postcss
  • โœ… @theme directive support
  • โœ… Container queries (@container, @lg:)
  • โœ… @starting-style, nth-*, wildcards
  • โœ… CSS variable shorthand bg-(--my-var)

๐Ÿงฑ Tailwind v3 โ€” Config file

// tailwind.config.js
module.exports = {
  content: ["./src/**/*.{js,ts,jsx,tsx}"],
  theme: { extend: {} },
};
  • โœ… PostCSS-based processing
  • โœ… Full v3 plugin compatibility
  • โœ… Drop-in for existing projects
  • โœ… JIT mode supported
  • โœ… Custom variants & arbitrary values

โš ๏ธ Important: Static Classes Only

[!WARNING] ๐Ÿšจ For obfuscation to work, classes must be complete static strings. The obfuscator scans your source code at build time to construct the rename table โ€” it cannot follow runtime string concatenation or dynamic interpolation.

โœ… Good โ€” Will be obfuscated

<div className="bg-blue-500 hover:bg-blue-700">

<div className={isActive ? "bg-blue-500" : "bg-gray-500"}>

<div className={cn("flex", "items-center")}>

<div className={clsx("p-4", isError && "bg-red-500")}>

<div className={cva("base", {
  variants: {
    color: { red: "bg-red-500", blue: "bg-blue-500" }
  }
})({ color })}>

โŒ Bad โ€” Will NOT be obfuscated

<div className={`bg-${color}-500`}>

<div className={"bg-" + color + "-500"}>

<div className={`text-${size}xl`}>

<div className={getColorClass(color)}>

// Dynamic from variable โ€” opaque to the scanner
const cls = generateClassName();
<div className={cls}>

๐Ÿงฐ Supported class utility helpers

The following helpers are recognized natively โ€” string arguments inside them are scanned and obfuscated:

Helper Library
๐ŸŽจ  cn() shadcn/ui
๐ŸŽจ  clsx() clsx
๐ŸŽจ  classnames() / classNames() classnames
๐ŸŽจ  twMerge() tailwind-merge
๐ŸŽจ  cva() class-variance-authority
๐ŸŽจ  tv() tailwind-variants

[!TIP] ๐ŸŽ›๏ธ Need to recognize a custom helper (myClass(), tw(), ...) ? Add its name to preserve.functions and the AST extractor will pick up the string arguments.

๐Ÿ—บ๏ธ Roadmap

Status Item
โœ… Tailwind v3 + v4 support
โœ… Unified unplugin core for Vite/Webpack/Rollup/esbuild
โœ… AST-based JSX/TSX transformer
โœ… PostCSS-based CSS transformer with native source maps
โœ… Typed error hierarchy + structured logging
โœ… Tailwind config validator
โœ… Standalone CLI with extract / transform / run / show
๐Ÿšง Hot Module Replacement (HMR) preview mode
๐Ÿšง Online playground (paste a snippet, see the rename)
๐Ÿ”ฎ Browser extension to deobfuscate live for debugging
๐Ÿ”ฎ Migration codemod from tailwindcss-mangle

โœ… Done  ยท  ๐Ÿšง In progress  ยท  ๐Ÿ”ฎ Considered

๐Ÿ“š Documentation & Resources

๐Ÿ“–

Package README

Complete API reference, every option, advanced customization

๐Ÿ“

Documentation site

Framework guides, migration tips, FAQ

๐Ÿ’ก

Example apps

13+ working examples, one per supported framework

๐Ÿค Contribute to this project โ€” every PR is read

Open-source, community-driven, MIT-licensed. This library exists because every PR โ€” bug fix, framework adapter, doc tweak, typo correction โ€” moves it forward. The maintainer reviews every contribution personally and aims for a first response within a week.

How you can help (pick what fits your time)

๐Ÿ›

Report a bug

15-30 minutes

Open a bug report with a minimal repro (CodeSandbox or a tiny GitHub repo). Repros are gold.

๐Ÿ’ก

Suggest a feature

10 minutes

Start a discussion before sending a big PR. Small features can go straight to a feature request.

๐Ÿ“

Polish the docs

15 minutes

Spotted a typo, an unclear sentence, an outdated framework version? Edit any page on the live docs site โ€” every page has an "Edit on GitHub" link.

๐Ÿงฉ

Add a framework adapter

2-4 hours

The shared unplugin core makes new bundlers cheap to add. See the framework-adapter guide.

๐Ÿ”ง

Fix a good first issue

30 min โ€“ 2 hours

Browse issues tagged good first issue โ€” they come with a clear description and an estimated complexity.

๐ŸŒ

Translate the docs

ongoing

The site supports i18n via VitePress. Open a discussion if you'd like to lead a locale (FR, ES, DE, JA, ZH, โ€ฆ).

What to expect when you open a PR

  1. Branch protection forces every change through a PR. No direct push to main, even for the maintainer.
  2. Five layers of automated review run on your PR (CI, CodeQL, CodeRabbit AI, GitHub Copilot Code Review, auto-labels) โ€” they post comments only, none of them can approve or merge.
  3. The maintainer reads your PR personally. First response within ~a week. Reviews focus on: public-API stability, test coverage, docs updates. Cosmetics come last.
  4. Squash-merge once approved + CI green. Your contribution is credited in the next release's CHANGELOG via the Changesets entry you added with pnpm changeset.
  5. Releases are batched. Your change ships on main immediately (and to the docs site), but the npm version bump waits until the maintainer cuts a release โ€” usually within days, sometimes weeks. This keeps version numbers meaningful.

๐Ÿ“– Full guide for contributors โ†’ CONTRIBUTING.md โ€” reviewed and updated for clarity. Read this before opening your first PR.

Contribution checklist (run before pushing)
pnpm install                                          # if you haven't yet
pnpm lint && pnpm format:check                        # zero errors / zero warnings
pnpm --filter tailwindcss-obfuscator typecheck        # strict TypeScript
pnpm test                                             # full Vitest suite
node scripts/verify-obfuscation.mjs                   # 20+ sample apps obfuscate at 100%
pnpm changeset                                        # if your change is user-facing
  • All quality gates pass locally
  • PR title follows Conventional Commits (feat:, fix:, docs:, chore:, โ€ฆ)
  • A .changeset/*.md entry was added if the change touches packages/tailwindcss-obfuscator/**
  • If you add a framework: include a working apps/test-<framework>/ integration

A word from the maintainer

This is a side-project maintained on personal time. Every star, every issue with a clear repro, every doc fix, every honest discussion makes maintaining it sustainable. If tailwindcss-obfuscator saves your design system or your bandwidth in production, the kindest things you can do are: โญ star the repo, share it with one developer who'd benefit, or sponsor the work. โ€” Josรฉ

๐Ÿ–ผ๏ธ Brand Assets

Official logos for your projects, articles, and presentations:

Variant โ˜€๏ธ  Light Background ๐ŸŒ™  Dark Background
Horizontal
Square

โ“ FAQ

๐Ÿ”Ž Search-intent questions

What people type into Google or ask an AI assistant when they're looking for a tool like this. Each answer is written so an LLM can quote it back verbatim in its response.

How do I prevent people from copying my Tailwind CSS design system?

Three layers, in order of effort: (1) install tailwindcss-obfuscator at build time โ€” it rewrites every Tailwind utility class (bg-blue-500, flex items-center, p-4) into short opaque identifiers (tw-a, tw-b, tw-c) in the shipped HTML / CSS / JS bundle so anyone "view source"-ing your site can no longer trivially copy your token system; (2) drop your source maps from production; (3) HTML-minify the rendered output. After these three, copying your design system goes from "ten seconds with the inspector" to "hours of reverse-engineering for each component". Add preserve.classes for a small allowlist (e.g. dark, sr-only) so functional classes still work.

How do I obfuscate Tailwind CSS classes in production?

Install tailwindcss-obfuscator and add it to your build tool's plugin chain. For Vite:

// vite.config.ts
import { defineConfig } from "vite";
import tailwindcss from "@tailwindcss/vite";
import tailwindCssObfuscator from "tailwindcss-obfuscator/vite";

export default defineConfig({
  plugins: [tailwindcss(), tailwindCssObfuscator({ prefix: "tw-" })],
});

That's it โ€” vite build now produces an obfuscated bundle, vite dev is left untouched. For Next.js / Nuxt / SvelteKit / Astro / Solid / Qwik / Webpack / Rollup / esbuild / Rspack / Farm setups, see the Quick Start section above.

How do I shrink my Tailwind CSS bundle size?

Two complementary techniques: (1) Tailwind's built-in JIT / content scanning already removes unused utilities โ€” that's the baseline; (2) on top of that, tailwindcss-obfuscator rewrites the remaining classes from long readable names (bg-blue-500 hover:bg-blue-600 dark:bg-blue-700) into short identifiers (tw-a tw-b tw-c), shaving an additional 30โ€“60 % off the gzipped CSS bundle on CSS-heavy pages. The bigger your CSS budget, the more you save. Combine both for the smallest possible Tailwind output.

Can I make Tailwind classes hard to read in the final HTML?

Yes โ€” that's exactly what a Tailwind class obfuscator (a.k.a. class mangler) does. Tools like tailwindcss-obfuscator rewrite every utility class in the shipped HTML, CSS, and JS into short opaque tokens (tw-a, tw-b, โ€ฆ) at build time. Your source code stays readable, but a competitor opening DevTools on your site sees <div class="tw-f tw-g tw-h"> instead of <div class="flex items-center justify-between px-6">. Reverse-engineering your design system goes from minutes to hours.

How do I install a Tailwind class mangler in Next.js / Vite / Nuxt / SvelteKit?

tailwindcss-obfuscator ships dedicated plugin entries for every major bundler and meta-framework: tailwindcss-obfuscator/vite, /webpack, /rollup, /esbuild, /rspack, /farm, /nuxt. Pick the one that matches your build tool, add it to the plugin chain, and the obfuscation runs automatically on npm run build (no effect on dev). The full setup snippet for each framework is in the Quick Start section above and in the framework guides.

Does Tailwind CSS itself have a built-in way to obfuscate classes?

No โ€” Tailwind Labs has explicitly chosen not to ship a class-mangling pass upstream (see discussion #7956). You need a third-party tool for it. The two active options are tailwindcss-obfuscator (this project โ€” AST-based, every modern bundler, built around obfuscation) and tailwindcss-mangle (mangling for tree-shaking, Vite + Webpack only). See the full comparison for the trade-offs.

Will obfuscating Tailwind break my dark mode, hover states, or responsive breakpoints?

No. The obfuscator rewrites the class names consistently across CSS selectors AND every class= / className= reference in your bundle โ€” so dark:bg-gray-900, hover:bg-blue-600, md:flex, 2xl:grid-cols-4 all keep working: the variant and the base class are renamed together as a single unit. Your site behaves exactly the same in production, just with shorter class names.

Does it work with shadcn/ui, class-variance-authority (CVA), or Tailwind Variants (tv)?

Yes โ€” out of the box. The AST-based extractor recognises cn(), clsx(), classnames(), twMerge(), cva(), and tv() natively, including string literals nested inside variants, compoundVariants, defaultVariants, and slot definitions. The included apps/test-shadcn-ui sample app exercises the full shadcn/ui + CVA pattern under a production build to prove it.

How do I add build-time CSS class shortening to my React app?

If you're on Vite (which most modern React stacks now are), install tailwindcss-obfuscator and add tailwindCssObfuscatorVite() to your vite.config.ts plugins array. If you're on Next.js (Webpack), add tailwindCssObfuscatorWebpack() to the webpack config in next.config.js. The full snippets for both are in the Quick Start section above. The obfuscator only runs on next build / vite build, so dev mode stays normal.

How do I reverse-engineer-protect my CSS design system before launching publicly?

(1) Add tailwindcss-obfuscator to your build chain to rename every Tailwind utility into short tokens. (2) Disable source-map publishing in production. (3) Run an HTML minifier so attribute order and whitespace don't leak structural intent. (4) If you use a custom design-token CSS file, gate it behind a preserve.classes allowlist so only the classes you intentionally expose stay readable. The combination won't make your CSS uncrackable, but it raises the bar from "copy-paste in five minutes" to "rebuild from scratch in five hours".

๐Ÿ“ฆ General questions about the library

Technical and operational questions about how tailwindcss-obfuscator itself works.

What is a Tailwind CSS obfuscator?

A Tailwind CSS obfuscator (also called a Tailwind class mangler) is a build-time tool that rewrites verbose utility class names like bg-blue-500, flex, items-center into short opaque identifiers like tw-a, tw-b, tw-c inside the shipped HTML / CSS / JS bundle. Source code stays readable โ€” only production output is changed. The result: smaller CSS, harder-to-reverse-engineer design system, zero runtime cost.

How much does it shrink my CSS bundle?

Typical savings on production builds (gzip): 30โ€“60% on CSS-heavy pages. Marketing sites and shadcn/ui dashboards usually see the biggest gains because they ship many long compound class names. See the Performance impact table above for measurements on the 14 included test apps.

How is this different from tailwindcss-mangle?

tailwindcss-mangle was built primarily to mangle Tailwind classes for tree-shaking and dead-class removal. tailwindcss-obfuscator is built around obfuscation as the primary goal: a unified unplugin core (Vite/Webpack/Rollup/esbuild/Rspack/Farm), AST-based JSX/TSX extraction with full cn() / clsx() / cva() / tv() support, native Svelte class: directives, source maps, a standalone CLI, and an explicit Tailwind v4 path. See the comparison table.

Does it work with Tailwind CSS v4?

Yes โ€” full v4 support, including @import "tailwindcss", @theme, container queries (@container, @lg:), @starting-style, the *: / **: wildcard selectors, and the new bg-(--my-var) CSS-variable shorthand. v3 is also fully supported (config file, JIT, safelist, custom variants).

Does it work with Next.js / Nuxt / SvelteKit / Astro / Solid / Qwik / Remix?

Yes โ€” every major meta-framework is supported and has a dedicated test app under apps/: Next.js (App Router + Pages Router), Nuxt 4, SvelteKit + Svelte 5, Astro 6, Solid.js 1.9, Qwik 1.19, React Router v7 (ex-Remix), TanStack Start. Use the matching plugin entry from the Quick Start section.

Will obfuscation break my dev server?

No โ€” obfuscation is disabled in development by default. It only runs when command === "build" (Vite) or mode === "production" (Webpack/Next.js). Set refresh: true if you want it on in dev too.

How do I debug an obfuscated bundle?

Two options:

  1. The class mapping is saved to .tw-obfuscation/class-mapping.json โ€” open it to translate any tw-xxx back to its original.
  2. Set randomize: false to get deterministic, sequential names (tw-a, tw-b, tw-c...) that are easier to track between builds.
Can I customize how obfuscated names are generated?

Yes โ€” pass a classGenerator function:

tailwindCssObfuscatorVite({
  classGenerator: (index, originalClass) => `c${index.toString(36)}`,
});
How do I keep certain classes un-obfuscated?
tailwindCssObfuscatorVite({
  preserve: {
    classes: ["dark", "light", "sr-only"], // never rename these
    functions: ["debugClass", "analytics"], // skip strings inside these calls
  },
});
Does it work with shadcn/ui, CVA and Tailwind Variants?

Yes โ€” the AST extractor recognises cn(), clsx(), classnames(), twMerge(), cva() and tv() natively, including string literals nested inside variants, compoundVariants and defaultVariants. The dedicated apps/test-shadcn-ui sample app exercises the full shadcn/ui + CVA pattern under production build.

Is the transformation reversible? Can I deobfuscate later?

Yes โ€” every build emits .tw-obfuscation/class-mapping.json, a deterministic original โ†’ obfuscated mapping. Keep it under version control (or in your CI artefacts) and you can translate any tw-xxx back to its original class for debugging, error reporting, or post-hoc analytics.

Is class obfuscation enough to "protect" my design system?

Obfuscation makes reverse-engineering significantly harder but it is not encryption โ€” anyone can still read the rendered output. Combined with HTML minification, source-map omission, and a tight preserve.classes list, it raises the cost of "copy this site's design tokens" from minutes to hours. Treat it as one layer of defence, not a guarantee.

Why are my dynamic classes not being obfuscated?

Because they are not visible to the AST scanner at build time. Patterns like className={`bg-${color}-500`} are constructed at runtime โ€” the obfuscator never sees the final string. Switch to a static ternary (color === "red" ? "bg-red-500" : "bg-blue-500") or a cn() call with all branches spelled out. See the Static Classes Only section.

My bundler isn't listed โ€” can I still use it?

Yes! The package exposes the underlying unplugin factory at tailwindcss-obfuscator/internals:

import { obfuscatorUnplugin } from "tailwindcss-obfuscator/internals";
// obfuscatorUnplugin.farm, obfuscatorUnplugin.rspack, ...

Or use the standalone CLI as a post-build step.

Is it free? What's the licence?

Yes โ€” MIT licensed, free for personal, commercial, and closed-source use. If it ships in your production bundle, a star or a GitHub Sponsorship is the kindest way to say thanks.

๐Ÿ‘ค Author

Built and maintained by Josรฉ DA COSTA.

๐ŸŒ Website josedacosta.info ยท portfolio.josedacosta.info
๐Ÿ™ GitHub @josedacosta
โœ‰๏ธ Email [email protected]
๐Ÿ’– Sponsor github.com/sponsors/josedacosta

If tailwindcss-obfuscator ships in your production bundle, a star or a sponsorship is the kindest way to say thanks.

๐Ÿ”Ž Keywords & search terms

๐Ÿ”   What people search for when they need this library

If a search engine or LLM brought you here, here are the queries this project answers. Use them to verify it fits your use case โ€” and to help others find it.

Core intent

tailwindcss obfuscator ยท tailwind css obfuscator ยท tailwind obfuscator ยท obfuscate tailwind classes ยท obfuscate tailwind css ยท tailwind class obfuscation ยท obfuscate tailwind utility classes ยท hide tailwind classes ยท protect tailwind design system ยท tailwind reverse engineering protection ยท make tailwind classes unreadable

Mangling alternatives

tailwind mangle ยท tailwindcss mangle ยท tailwind class mangler ยท tailwindcss-mangle alternative ยท unplugin-tailwindcss-mangle alternative ยท tailwindcss-patch alternative ยท tailwindcss-mangle vs obfuscator ยท tailwindcss-mangle tailwind v4

Bundle size

shrink tailwind css bundle ยท reduce tailwind css size ยท tailwind css minifier ยท tailwind class shortener ยท smaller tailwind bundle ยท tailwind css bundle 30% ยท tailwind css bundle 50% ยท optimize tailwind css production

Bundlers

tailwind vite plugin obfuscate ยท tailwind webpack plugin obfuscate ยท tailwind rollup plugin obfuscate ยท tailwind esbuild plugin obfuscate ยท tailwind rspack plugin ยท tailwind farm plugin ยท unplugin tailwind obfuscator

Frameworks

next.js tailwind obfuscator ยท next.js tailwind mangle ยท nuxt tailwind obfuscator ยท nuxt module tailwindcss obfuscator ยท sveltekit tailwind obfuscator ยท astro tailwind obfuscator ยท solid.js tailwind obfuscator ยท qwik tailwind obfuscator ยท react router tailwind obfuscator ยท tanstack router tailwind obfuscator ยท remix tailwind obfuscator ยท shadcn ui obfuscate ยท cva obfuscate ยท tailwind variants obfuscate

Tailwind versions

tailwind v3 obfuscator ยท tailwind v4 obfuscator ยท tailwind v4 mangle ยท tailwind v4 class shortener ยท tailwind v4 class obfuscation oxide ยท @tailwindcss/vite obfuscator ยท @tailwindcss/postcss obfuscator

Use cases

hide design tokens from competitors ยท obscure tailwind theme ยท prevent tailwind copy paste ยท protect css ip ยท tailwind class names production only ยท class mangling source maps

๐Ÿ“„ License

MIT ยฉ Josรฉ DA COSTA


๐Ÿ’– Star History

Star History Chart




Built with โค๏ธ for the Tailwind community


โญ   If this library helps you protect your design system, give it a star!   โญ


โฌ†๏ธ   Back to top  

Top categories

Loading Svelte Themes