A variant applies a class only while a condition holds on the player’s client. Write it as a colon prefix, as in Tailwind:
<frame className="w-full md:w-1/2 lg:w-1/3" />Chain prefixes to require every condition. The order inside a chain doesn’t matter.
<frame className="hidden touch:portrait:visible" />| Variant | Matches when |
|---|---|
sm md lg xl 2xl | viewport width is at least 640, 768, 1024, 1280, 1536 |
max-sm … max-2xl | viewport width is below that same threshold |
attr-[Name=value] | the styled instance carries that Roblox attribute |
portrait | viewport width is less than viewport height |
landscape | viewport width is greater than or equal to viewport height |
touch | the active input mode is touch |
mouse | the active input mode is mouse |
gamepad | the active input mode is gamepad |
hover | the pointer is over this element |
active | this element is being pressed |
focus | this element holds focus or selection |
dark | the local player carries VelaColorScheme = "dark" |
group-hover group-active group-focus | the nearest ancestor marked group is in that state |
peer-hover peer-active peer-focus | a sibling marked peer is in that state |
There is no not- form and no disabled:. An unknown prefix reports unknown-variant, and the
token is dropped.
Which class wins
The order you write classes in doesn’t decide. Vela ranks them the way Tailwind’s stylesheet does, weakest first:
- Base classes.
- States:
hover:,active:,focus:, attribute variants,group-*,peer-*. - Breakpoints, narrowest first, so a wider one wins. A
max-*ranks as a breakpoint with no minimum. portrait:/landscape:,dark:, and the input variants.
Within one rank, the class written last wins. So:
hover:bg-blue-500 bg-red-500turns blue under the pointer.lg:p-8 md:p-4isp-8on a wide screen.dark:bg-blue-500 md:bg-red-500is blue in dark mode, even on a wide screen.
Breakpoints, and their complements
| Variant | Applies when | Complement |
|---|---|---|
sm: | width >= 640 | max-sm: — width < 640 |
md: | width >= 768 | max-md: — width < 768 |
lg: | width >= 1024 | max-lg: — width < 1024 |
xl: | width >= 1280 | max-xl: — width < 1280 |
2xl: | width >= 1536 | max-2xl: — width < 1536 |
max-md: is the exact complement of md:. At exactly 768px, md: applies and max-md: doesn’t.
Chain the two to target one range:
<frame className="md:max-lg:w-1/2" />A chain that matches no width, such as lg:max-md:, reports invalid-breakpoint-range.
Write the small-screen style unprefixed and layer wider screens on top. To rename or add
breakpoints, use theme.screens. One entry defines both
the bare prefix and its max- form.
Breakpoints follow the viewport live, so resizing the window re-applies them.
How orientation is derived
landscape means the viewport is at least as wide as it is tall. Anything else is portrait.
A square viewport counts as landscape. If your layout has a square case, test it.
How input mode is detected
Exactly one input mode is active at a time. Vela picks it by priority from UserInputService, not
by the device used last:
gamepadifGamepadEnabledis true.- Otherwise
touchifTouchEnabledis true. - Otherwise
mouse.
So a device with both a gamepad and a touchscreen matches gamepad:, not touch:. Plugging in a
controller mid-session switches the mode right away.
Hover, active and focus are per-element
These three track the element itself rather than the screen:
| Variant | Tracked through |
|---|---|
hover | MouseEnter / MouseLeave |
active | InputBegan / InputEnded, for mouse and touch. Also clears on MouseLeave, so dragging off a button doesn’t leave it stuck. |
focus | Focused / FocusLost on a textbox. Gamepad SelectionGained / SelectionLost elsewhere. |
Vela only listens on elements that use the variant. Event handlers you wrote yourself keep working.
Add transition to tween the change instead of snapping it (see
motion utilities):
<textbutton className="w-28 h-10 rounded-md bg-sky-500 hover:bg-sky-600 active:bg-sky-700 focus:ring-2 transition duration-150" Text="Play"/>Gamepad and touch players may never hover. Use hover: as extra feedback only. A controller player
sees focus:.
Group and peer
You can style an element from another element’s state. Mark an ancestor group and read it with
group-hover:, group-active: or group-focus:. Mark a sibling peer and read it with peer-*:
<textbutton className="group flex gap-2 bg-slate-800"> <textlabel className="text-slate-300 group-hover:text-white" Text="Settings" /></textbutton>To pick one group out of several, name it. group/card marks it, and group-hover/card: reads the
nearest group/card ancestor, skipping unnamed groups in between. peer/email and
peer-focus/email: work the same way.
Groups and peers can also be read through attribute variants: group-selected: for a registered
selected variant, group-attr-[State=open]/card:, or peer-attr-[Tier=2]:. A / inside the
brackets is part of the value.
A few things differ from CSS:
- Any marked sibling is a peer, not only an earlier one, because Roblox has no sibling order. Several peers combine with OR.
- Group hover is geometric. A child drawn outside the group’s bounds doesn’t hover the group.
- A marker can’t be conditional.
hover:groupwarnsconditional-marker. - Put the marker on a host element, not a component. On a component it warns
marker-on-component. - Only element states can be read.
group-md:warnsunsupported-relational-variant.
A marker becomes a CollectionService tag, VelaGroup or VelaPeer, merged with any Tag you set:
<frame Tag="Card" className="group/card"> emits Tag="Card VelaGroup/card". The marked element
stays on the static path. Only the elements that read it use the runtime host. Because the lookup
walks the instance tree, it works across components, across files, under Vide, and past a margin on
either element.
Dark mode is state your app owns
Roblox doesn’t tell a game the player’s color scheme, so your app sets it. dark: matches when
Players.LocalPlayer has a VelaColorScheme attribute set to "dark":
Players.LocalPlayer.SetAttribute("VelaColorScheme", prefersDark ? "dark" : "light");<frame className="bg-white dark:bg-zinc-900" />Any other value, or no attribute at all, means light. Changing the attribute restyles every dark:
element immediately.
State your UI owns
For your own states, like a panel being open or a row being selected, style off a Roblox attribute on the element. Write it inline:
<frame className="rounded-sm attr-[State=open]:rounded-lg" />Or register a name for it in vela.config.ts:
plugin(({ addVariant }) => { addVariant("open", { attribute: "State", equals: "open" });});<frame className="rounded-sm open:rounded-lg" />Set the attribute the way you set any other:
<frame ref={(f) => f?.SetAttribute("State", isOpen ? "open" : "closed")} />equals takes a string, number or boolean. Custom variants chain with every other variant and get
the same editor support as built-in ones. Attributes replicate from the server and show in Studio,
so your styles read the same state the rest of the game does.
The names group and peer, and any name starting with group- or peer-, are reserved.
addVariant throws on them.
The cost: any variant forces the runtime path
Any variant prefix moves that element onto the
runtime path, even in a plain string
literal like className="sm:w-full". The element renders through VelaRuntimeHost instead of
getting plain props.
The cost is small:
- The file imports
@rbxts/vela-runtime, one ModuleScript the whole place shares, plus a few hundred bytes of config. - Each runtime-path element re-checks its rules when the viewport, input mode or color scheme changes. All hosts share one set of signal connections, made the first time one needs them.
The compiler still resolves and checks every variant class, so you keep diagnostics and the full utility set.
Use variants where they pay off: top-level containers that reflow between phone and desktop, a gamepad-only hint, hover feedback on controls. Keep leaf components on plain classes.
Driving reflow yourself
To keep a file off the runtime host entirely, read the viewport yourself and switch between two static class strings. Both branches stay on the static path:
function useViewportWide(threshold: number) { const [wide, setWide] = React.useState(false);
React.useEffect(() => { const camera = Workspace.CurrentCamera; if (!camera) return; const update = () => setWide(camera.ViewportSize.X >= threshold); const connection = camera.GetPropertyChangedSignal("ViewportSize").Connect(update); update(); return () => connection.Disconnect(); }, [threshold]);
return wide;}
export function Shell(props: { children?: React.Element }) { const wide = useViewportWide(768);
return wide ? ( <frame className="flex gap-4 p-4 w-full h-full">{props.children}</frame> ) : ( <frame className="flex flex-col gap-2 p-2 w-full h-full">{props.children}</frame> );}See also
- Dynamic class names: the other way onto the runtime path, and what it costs.
- Utilities reference: Motion: transitions and animations that pair with variants.
- Layout and sizing: the utilities you’ll most often vary by breakpoint.
- Diagnostics: every warning code.