px
API reference for the `px` function
Overview
The px allows you to combine multiple pseudo-class strings into one unified selector.
Available to clients only
If you require AST parsing and compilation for an RSC preview such as Next.js, you cannot use these zss-utils libraries and must instead define static variables using the defineConsts API.
It’s useful when working with Plumeria’s pseudo utilities like ps.hover
, ps.active
, or custom ps.fn.has()
.
The result is a single joined pseudo selector string that can be passed into css.create()
or other style utilities.
Purpose
When defining styles for complex pseudo states (:hover:focus
, :has(div):focus-visible
, etc.), manually writing strings becomes error-prone.
The px()
function recommend type-safe composition of pseudo strings while preserving string literal types for DX and autocomplete.
Example
You can use the combined result in your styles:
Return value
Returns a joined pseudo selector string, preserving literal types:
Use cases
- Combine standard pseudo-classes:
- Combine functional and state pseudo-classes:
Type-safety benefit
px()
preserves string literal types, you get full type-checking and editor autocomplete — even for composed pseudo selectors.