Hover, Focus and Other States
Please refer to the documentation on the Tailwind CSS website for more information.
Pseudo-classes β
If a <View />
has a class which requires an event listener, it will be automatically upgraded to <Pressable />
.
Hover, focus, and active β
NativeWind implements a subset of the Tailwind pseudo-classes by adding event listeners on your components, hence they will only work on components that can accept the listener.
The supported pseudo-classes and their related listeners are:
Variant | Event Listeners |
---|---|
hover | onHoverIn , onHoverOut |
focus | onBlur , onFocus |
active | onPressIn , onPressOut , |
Opt in Pointer Eventsβ
React Native 0.71 supports opt-in Pointer Events. If enabled NativeWind will use these instead, allowing for hover support on native when used with a pointer device.
Variant | Event Listeners |
---|---|
hover | onPointerOver , onPointerOut |
focus | onBlur , onFocus |
active | onPressIn , onPressOut , |
First, last, odd, and even β
Class | Support |
---|---|
first: | π Web only |
last: | π Web only |
odd: | π Web only |
even: | π Web only |
Form States β
Class | Support |
---|---|
disabled: | βοΈ Partial Support |
required: | π Web only |
invalid: | π Web only |
On native, "disabled:"
is only available for components with a disabled
prop.
Unfortunately <TextInput>
uses enabled={false}
instead of disabled={true}
, so it will not work with "disabled:"
.
We are looking for contributors to add more support for "disabled:"
.
Styling based on parent state β
Styling based on parent state (group-{modifier})
NativeWind supports the group
class name and it can be used with any supported modifier.
Differentiating nested groups
NativeWind supports the group/{name}
class name and it can be used with any supported modifier
Arbitrary groups
Class | Support |
---|---|
Class selectors | β Full Support |
Attribute selectors | β Full Support |
Pseudo-classes selectors | π Web only |
Pseudo-elements selectors | π Web only |
Elements selectors | π Web only |
Moving group via `&` | π Web only |
Native supports multiple selectors, e.g group-[.classOne.classTwo[attribute=value]]
Styling based on sibling state β
Styling based on parent state (peer-{modifier})
Class | Support |
---|---|
peer | π Web only |
peer-* | π Web only |
peer-invalid | π Web only |
Styling direct children β
Styling based on parent state (*-)
Class | Support |
---|---|
*- | π Web only |
Styling based on descendants β
Styling based on descendants (has-{modifier})
Class | Support |
---|---|
has- | π Web only |
We are looking for contributors to add more support for has-
.
Pseudo-elementsβ
Placeholder textβ
On native, placeholder:
only supports the text-*
or color-*
classes. It will map to the placeholderTextColor
on native.
We are looking for contributors to add more support for placeholder:
.
Class | Support |
---|---|
placeholder: | βοΈ Partial Support |
Media and feature queriesβ
Responsive breakpointsβ
To style an element at a specific breakpoint, use responsive modifiers like md
and lg
.
Check out the Responsive Design documentation for an in-depth look at how these features work.
Prefers color schemeβ
Please read the Dark Mode documentation for an in-depth look at how this feature works.
Class | Support |
---|---|
dark: | β Full Support |
Prefers reduced motionβ
Class | Support |
---|---|
motion-reduce: | β Full Support |
Viewport orientationβ
Use the portrait and landscape modifiers to conditionally add styles when the viewport is in a specific orientation.
Class | Support |
---|---|
portrait: | β Full Support |
landscape: | β Full Support |
Print stylesβ
Use the print modifier to conditionally add styles that only apply when the document is being printed:
Class | Support |
---|---|
print: | π Web only |
Supports rulesβ
Use the supports-[...] modifier to style things based on whether a certain feature is supported in the userβs browser.
Class | Support |
---|---|
supports-[n]: | π Web only |
Attribute selectorsβ
Use the aria-* modifier to conditionally style things based on ARIA attributes.
Class | Support |
---|---|
aria-[n]: | π Web only |
Data selectorsβ
Use the data-* modifier to conditionally style things based on data attributes.
Class | Support |
---|---|
data-[n]: | π Web only |
RTL supportβ
Use the rtl and ltr modifiers to conditionally add styles in right-to-left and left-to-right modes respectively when building multi-directional layouts:
Class | Support |
---|---|
ltr: | β Full Support |
rtl: | β Full Support |
Open/closed stateβ
Use the open modifier to conditionally add styles when a <details/>
or <dialog/>
element is in an open state:
Class | Support |
---|---|
open: | π Web only |
Custom modifiersβ
Custom modifiers are possible, but are not yet documented. More information to come.