Type aliases
DarkMode
DarkMode: "media" | "class" | false
Falsy
Falsy: "" | 0 | 0 | false | null | undefined | void
Hasher
Hasher: (value: string) => string
Type declaration
-
-
Parameters
Returns string
MaybeArray
MaybeArray<T>: T | readonly T[]
Type parameters
MaybeThunk
Maybe
Thunk<T>: T | ((context: Context) => T)
Type parameters
Plugins
Plugins
: Record<string, Plugin | undefined>
Prefixer
Prefixer: (property: string, value: string, important?: boolean) => string
Type declaration
-
- (property: string, value: string, important?: boolean): string
-
Parameters
-
property: string
-
value: string
-
Optional important: boolean
Returns string
ReportInfo
ReportInfo: { id: "LATE_SETUP_CALL" } | { id: "UNKNOWN_DIRECTIVE"; rule: string } | { id: "UNKNOWN_THEME_VALUE"; key: string | undefined } | { css: string; error: Error; id: "INJECT_CSS_ERROR" }
SheetInitCallback
SheetInitCallback<T>: (value?: T) => T
Type parameters
ThemeFontSize
ThemeFontSize: string | [size: string, lineHeight: string] | [size: string, options: { letterSpacing?: string; lineHeight?: string }]
ThemeOutline
ThemeOutline: [outline: string, offset: string]
ThemeScreenValue
ThemeScreenValue: string | { raw: string } | { max?: string; min: string } | { max: string; min?: string }
ThemeSection
Type parameters
ThemeSectionRecord
ThemeSectionRecord<T>: Record<string, T | undefined>
Type parameters
ThemeSectionResolver
Type parameters
ThemeSectionType
Type parameters
TypescriptCompat
TypescriptCompat: boolean | number
Unwrap
Unwrap<T>: T extends string[] ? string : T extends Record<string, infer R> ? R : T
Type parameters
Despite the module being very flexible and powerful, it was our intention to keep the surface API as minimal as possible. We appreciate that this module is likely to be used by developers & designers alike and so we try provide sensible defaults out of the box, with little to no need for customization.
Getting started with the library requires no configuration, build step or even installation if you use skypack or unpkg (see the Installation guide for more information).
Using the exported tw function without any setup results in the compilation of the rules like
bg-black text-white
andtext-xl
exactly as specified in the Tailwind documentation. For convenience the default tailwind theme is used along with the preflight base styles if neither are provided by the developer.Calling the tw function like in the example above results in the shorthand rules to be interpreted, normalized and compiled into CSS rules which get added to a stylesheet in the head of the document. The function will return a string consisting of all the class names that were processed and apply them to the element itself much like any other CSS-in-JS library.
tw
functionapply
functionsetup
functiontheme
helperInstallation
API
tw
functionIt is possible to invoke the tw function in a multitude of different ways. It can take any number of arguments, each of which can be an Object, Array, Boolean, Number, String or Template Literal. This ability is inspired heavily by the clsx library by Luke Edwards.
Show me more examples
Inline Plugins
Sometimes developers might want to break out of the defined Tailwind grammar and insert arbitrary CSS rules. Although this slightly defeats the purpose of using Tailwind and is not actively encouraged, we realize that is often necessary and so have provided an escape hatch for developers.
In the above example a class is generate for an
::after
pseudo element. Something that isn't possible within the confides of the Tailwind API nor possible to denote using a style attribute on an element.For a further explanation on this mechanism see Plugins.
apply
functionAs a component author, one often wants to re-use Tailwind directive styles for defining a component and allow users of the component to override styles using Tailwind rules. The created component can be used as a base for child components and override or add some styles using Tailwind rules.
apply generates one style object, e.g., one CSS class, combining all Tailwind rules by deep merging rules in order of declaration.
Using
apply
withinpreflight
Use Tailwind rules within
setup({ preflight })
.CSS
can be used withinapply
twind/css can be used to define additional styles.
Using within
CSS
apply
can be used withcss
:Using template literal syntax:
Using Tailwind directives with
animation
fromtwind/css
A React button component
setup
functionUnderstandably developers will more often than not want to customize the out of the box experience. It is possible to achieve this with the setup function. Doing so will ultimately change the behavior of calling the
tw
function, making it appropriate for your particular use case.The setup function is a named export of the Twind and accepts an config object as an argument.
theme
helperThe theme helper simplifies using theme values: