Twind Documentation
repository·main·Indexed 26 days ago
https://github.com/tw-in-js/twindTwind is a runtime Tailwind CSS compiler that converts utility classes into CSS on the fly, eliminating the need for a build-time PostCSS pipeline. It supports browsers, Node.js, and edge runtimes. The library includes a core engine (@twind/core), various presets such as @twind/preset-tailwind and @twind/preset-autoprefix, and specialized integration packages for frameworks including Next.js, Gatsby, SvelteKit, Remix, and Lit/Web Components. It also offers a lightweight CDN alternative to the Tailwind Play CDN.
What's inside Twind
- Twind is a lightweight, high-performance compiler that converts Tailwind utility classes into CSS at runtime. It unifies the flexibility of CSS-in-JS with the Tailwind API, allowing you to use utility-first CSS without a build step (no Tailwind, PostCSS, or purging required). It is framework-agnostic and works in browsers, Node.js, Deno, and edge workers.
Overview of @twind/intellisense
main@twind/intellisense provides IntelliSense utilities for twind. It is designed to enhance the developer experience by providing autocompletion and intelligence for Twind-related configurations and classes within supported editors.Integrate Twind with SvelteKit
mainUse@twind/with-sveltekitto achieve seamless integration of Twind with SvelteKit. This package allows you to use Tailwind CSS utility classes within your SvelteKit application using the Twind engine.Integrate Twind with Next.js
main@twind/with-next provides seamless integration of Twind with Next.js. For detailed setup instructions, configuration options, and implementation details, refer to the official documentation at twind.style/with-next.Use @twind/preset-autoprefix for CSS vendor prefixing
mainThe@twind/preset-autoprefixpackage is a preset for twind that provides CSS vendor prefixing and property alias mapping. It ensures that generated CSS works across different browsers by automatically adding necessary vendor prefixes.Use Twind CDN for browser-based Tailwind CSS
mainTwind CDN is a drop-in replacement for the Tailwind CSS Play CDN. It allows you to use Tailwind CSS directly in the browser without a build step. It is significantly smaller (approximately 17kB) compared to the Tailwind CSS Play CDN (approximately 104kB).Key Features of Twind
mainTwind provides several advantages for developers:
- No build step: Use Tailwind utility classes directly in the browser or server without PostCSS or configuration.
- Framework agnostic: Works with any HTML/JavaScript environment, including server-rendered apps.
- Low fixed cost: Ships the compiler instead of a large CSS file, allowing for unlimited styles and variants.
- Tailwind v3 parity: Features parity with Tailwind v3 syntax.
- Extensibility: Supports extended variants, rules, and syntax, as well as language extension via presets.
- Performance: Faster than most CSS-in-JS libraries and supports static extraction for zero runtime overhead.
- Type Safety: Written in TypeScript for strong typing.
- Tree shakeable: Only include the parts of the library you need.
Use @twind/preset-tailwind for a Tailwind CSS v3 experience
mainUse@twind/preset-tailwindto get the full Tailwind CSS v3 experience without a build step. It works in the browser and other environments like Node.js, Deno, and Workers.Use @twind/preset-radix-ui for Radix UI color scales
mainUse@twind/preset-radix-uito integrate Radix UI color scales into your Twind configuration. This preset provides automatic dark mode color support based on Radix UI's palette composition.Compare Twind with Tailwind CSS
mainWhen comparing Twind to the standard Tailwind CSS CDN, Twind offers a significantly smaller footprint (approximately 17kB vs 106kB via Brotli compression).
Key functional differences include:
- Predictable Utility Ordering: Unlike Tailwind CSS, which may have non-implicit ordering where the first utility used in a document wins if they share a CSS property, Twind ensures utility order is always predictable.
- Dark Mode: Twind supports custom selectors like
.dark-modeor[theme=dark]and provides auto dark colors.
Predictable CSS rule sorting
mainTwind ensures that generated CSS rules are sorted predictably and stably. The order of the rules remains consistent regardless of the order in which they are injected into the document.Integrate Twind with React using @twind/with-react
mainUse
@twind/with-reactto achieve seamless integration of Twind with React projects. This package provides the necessary glue to use Twind's utility-first CSS capabilities within the React ecosystem.For detailed implementation details, refer to the official documentation at twind.style/with-react.