Open-source project
tw-in-js/twind avatar
tw-in-js/twind

Twind: Tailwind utility classes compiled to CSS at runtime

The smallest, fastest, most feature complete Tailwind-in-JS solution in existence.

3,948 stars103 forksJavaScriptMIT

At a glance

What is it?
Twind is a small compiler that turns utility class names into CSS in the browser, in Node, in workers, or during a build. It targets teams that want Tailwind's API without a Tailwind build step, and it is worth adopting only if you accept runtime compilation or set up static extraction.
Who is it for?
Adopt Twind when you want Tailwind's class vocabulary in environments where a PostCSS pipeline is awkward: server-rendered apps, web components, CDN-only pages, workers, or a Node process that emits HTML. Skip it if your team has a working Tailwind build and no reason to move CSS generation into the runtime, or if you need a release cadence that matches Tailwind's own.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 5 days ago.
What is it written in?
Mainly JavaScript, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on September 30, 2026, and from our analysis. They are not legal advice.

Editorial analysis

The problem Twind solves: Tailwind classes without the Tailwind pipeline

Tailwind CSS normally means a build step. You install the framework, add a PostCSS or CLI pass, point it at your source files, and let it scan for class names so it can emit only the CSS you use. That works well in a bundled app. It is awkward in a server-rendered page that wants to emit styles per request, in a web component that ships as a single file, or in a page that has no bundler at all. Twind takes the other route. The README describes it as "a small compiler that converts utility classes into CSS at runtime", and the stated goal is to unify CSS-in-JS flexibility with the Tailwind API.

The audience follows from that. If your app is HTML plus JavaScript, the README says it should work with Twind, and that includes server-rendered apps. The examples directory backs this up with folders for Next, Remix, SvelteKit, Gatsby, Lit and plain web components, plus a CDN example and a playground. The project is not trying to replace Tailwind for teams that are happy with their build. It is aimed at the cases where shipping the compiler is cheaper than shipping the generated stylesheet.

How the runtime compiler works, and what the fixed cost means

Twind ships the compiler rather than the CSS. That sentence in the README is the whole architecture in one line. Instead of a generated stylesheet containing every utility you might use, the bundle contains the code that knows how to turn a class name such as a padding or flex utility into a CSS rule. When a class is seen, the compiler produces the rule and inserts it. The README calls this "one low fixed cost": unlimited styles and variants do not grow the bundle the way a prebuilt stylesheet would.

The trade-off is visible in the same list of features. Runtime compilation costs work in the browser, and the README answers that with static extraction, described as "no runtime overhead with static extraction". In other words, the same compiler can run ahead of time so the runtime does nothing. That is a meaningful split, and it is the decision most adopters have to make. Runtime compilation keeps the setup simple and handles classes that only exist at render time. Static extraction gives you the runtime profile of ordinary Tailwind but reintroduces a build step, which is the thing Twind was avoiding.

Two further mechanisms matter. Class names can optionally be hashed, which the README says ensures no conflicts, and the project supports conditional rule combining, so class strings can be built from expressions rather than concatenated by hand. The repository also lists @twind/with-web-components among recent releases, which is the integration path for custom elements. Twind is written in TypeScript and the README claims it is fully tree shakeable, so unused parts of the compiler can be dropped by a bundler.

Installing Twind and styling a first element

The README points at npm for the packages, and the badge links to @twind/core as the current release line. The monorepo requires Node >=14.15.0 and pnpm ^7.0.0 for development, but that constraint applies to working on Twind itself, not to consuming it. The README gives no install command, so the package name is the part to take from it: @twind/core is the package the release badge tracks, and the README says Twind is usable via CDN with no bundler required.

You then create a twind instance from a Tailwind config and use its tw function to produce class names. The documentation at twind.style has the full setup, and the repository's examples directory contains runnable projects for several frameworks, including examples/basic, examples/with-next, examples/with-remix and examples/with-sveltekit. The README does not print a code sample, so the setup itself has to come from the documentation rather than from a snippet here.

After that, tw is called with utility classes and returns the class string to place on an element. The compiler inserts the matching CSS. If you would rather not install anything, the README lists an example called using-twind-cdn. That is the fastest way to see the output: load the script, call tw on a class string, and inspect the stylesheet the page has grown. The playground at twind.run does the same thing without a local setup.

Where Twind is the wrong tool

The clearest limitation is the one the project itself advertises around. Runtime compilation moves work to the client. On a page with a small, fixed set of utilities, a normal Tailwind build produces a stylesheet that a browser can cache and that costs nothing to evaluate. Twind's runtime path evaluates the compiler instead. The README's answer is static extraction, but turning that on means you are running a build again, so the no-build-step benefit disappears for production and remains mainly a development convenience.

There is also a version-coupling problem. The README states feature parity with Tailwind v3, and the credits note that COPILOT TRAVEL partners with the maintainer "to keep twind aligned with the latest Tailwind CSS releases". Parity is a moving target: when Tailwind adds syntax, Twind has to catch up, and until it does, a class you copy from Tailwind documentation may not compile. The release history makes the cadence concrete. The most recent releases listed are [email protected], [email protected] and @twind/[email protected], all dated 2023-01-24, while the last push to the repository was on 2026-09-21. Activity on the repository and published package releases are not the same thing, and anyone planning to depend on a specific fix should check the changelog rather than assume a release followed.

Finally, this is a compiler, not a design system. It gives you Tailwind's grammar and an escape hatch for arbitrary CSS, but it does not give you components, theming decisions, or a migration path off Tailwind. Teams that want a component library should look elsewhere.

Twind compared with a plain Tailwind CSS build

The real alternative for most readers is not another CSS-in-JS library. It is Tailwind CSS itself, run through PostCSS or the Tailwind CLI. The difference is where the compilation happens and what you pay for it. Tailwind scans your source files at build time and emits a stylesheet containing exactly the utilities it found. The output is static, cacheable and free at runtime, and the cost is a build step plus a purge configuration that has to see every place a class name appears. Class names built by string concatenation are a known source of missing styles.

Twind inverts both sides. There is no scan step, so a class name assembled at runtime still works, which is a genuine advantage in server-rendered apps where the markup is not known until a request arrives. The price is that the compiler is part of your JavaScript payload unless you enable static extraction, and that the utility set tracks Tailwind's rather than being Tailwind's. If your build already works and your class names are static, the plain Tailwind route is simpler and has one less runtime dependency. Twind earns its place when the build step is the obstacle.

Licence, maintenance and upgrade cost

Twind is MIT licensed, and the repository root contains a LICENSE file that the README links to. MIT is permissive: you can use, modify and redistribute the code, including in commercial and closed-source products, provided the copyright notice and licence text are preserved. That is a description of the licence terms, not legal advice; if your organisation has a policy on third-party licences, run it past whoever owns that policy.

The upgrade cost is worth planning for. Twind v1 reached stable release on Nov 18, 2022, and the README points v0.16 users at a migration guide, so the project has already been through one breaking transition and expects another to be handled the same way. Because Twind tracks Tailwind's API, a Tailwind major version is also a Twind event. The monorepo uses changesets for versioning, which is why the packages carry independent version numbers rather than one shared version. If you pin @twind/core and a preset separately, read the changelog before bumping either.

Editorial conclusion

Adopt Twind when you want Tailwind's class vocabulary in environments where a PostCSS pipeline is awkward: server-rendered apps, web components, CDN-only pages, workers, or a Node process that emits HTML. Skip it if your team has a working Tailwind build and no reason to move CSS generation into the runtime, or if you need a release cadence that matches Tailwind's own. Before committing, verify which @twind package matches your version of Tailwind, check the licence file in the repository, and confirm that the twind.style documentation covers the framework integration you actually use.

Frequently asked questions

What does Twind mean?

The name is not defined in the repository or the README. The project is a Tailwind-in-JS compiler, and the README only uses the name as the project title.

Is Twind safe to use?

The README contains no security assessment. What it does state is that Twind is MIT licensed and that the compiler runs in the browser or another JavaScript environment, so the usual review of a runtime dependency applies.

Does Twind need a build step?

No. The README describes it as utility-first CSS without any build step, usable in the browser, in Node, in Deno and in workers, and it lists a CDN example with no bundler required. Static extraction is offered as an option when you want to remove the runtime cost.

Which package do I install to use Twind?

The README's release badge points at @twind/core, and recent releases also list gatsby-plugin-twind and @twind/with-web-components for those integrations. Framework-specific examples live in the examples directory of the repository.

Is Twind compatible with Tailwind v3?

The README states feature parity with Tailwind v3 and says the maintainer works to keep Twind aligned with the latest Tailwind CSS releases. Parity is maintained over time rather than guaranteed at any given moment, so check the changelog for the classes you rely on.

Official sources

  1. License: MIT
  2. Project website
  3. README
  4. Releases
  5. tw-in-js/twind on GitHub
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/tw-in-js-twind.svg)](https://hysenlabs.com/projects/tw-in-js-twind)