Velaguides

Layout and sizing

Flex, grid, padding, margins, size, position and transforms, and the Roblox layout instances they build.

Roblox has no CSS box model. Elements are placed by Position and AnchorPoint, sized by Size, and laid out by child instances like UIListLayout and UIPadding. Vela’s layout classes set those properties, or add those child instances for you.

src/client/Toolbar.tsx
<frame className="flex justify-between items-center gap-2">
<textlabel className="text-lg" Text="Inventory" />
<textbutton className="px-3 py-2 rounded-md bg-slate-700" Text="Close" />
</frame>
Nested lists: a column of two rows, each with its own UIListLayout.

Flex and UIListLayout

Flex, alignment, gap and wrap classes all go into one UIListLayout child.

flex and flex-row lay children out horizontally. flex-col lays them out vertically.

flex-row-reverse and flex-col-reverse report unsupported-flex-direction. Reorder the children instead, or use order-*.

justify-* splits across two properties

Roblox keeps alignment and spacing-out in separate properties, so justify-* writes to one of two:

ClassPropertyValue
justify-startHorizontalAlignmentEnum.HorizontalAlignment.Left
justify-centerHorizontalAlignmentEnum.HorizontalAlignment.Center
justify-endHorizontalAlignmentEnum.HorizontalAlignment.Right
justify-betweenHorizontalFlexEnum.UIFlexAlignment.SpaceBetween
justify-aroundHorizontalFlexEnum.UIFlexAlignment.SpaceAround
justify-evenlyHorizontalFlexEnum.UIFlexAlignment.SpaceEvenly

items-* and content-* work the same way on the vertical axis. items-start, items-center and items-end set VerticalAlignment. items-stretch sets VerticalFlex = Fill.

These classes don’t follow the flex direction. justify-* is always horizontal and items-* is always vertical, even under flex-col.

Wrapping and gap

flex-wrap and flex-nowrap set Wraps.

gap-{key} sets the list’s Padding. A list has one padding value, so there is no gap-x-* or gap-y-*. space-y-2 is short for flex flex-col gap-2, and space-x-2 for flex gap-2.

With divide-*, items sit gap + line thickness apart, as in CSS.

Flex items and UIFlexItem

These classes add a UIFlexItem child to the item itself. Several names map to the same mode:

ClassUIFlexItem property
flex-1FlexMode = Enum.UIFlexMode.Fill
flex-autoFlexMode = Enum.UIFlexMode.Fill
flex-initialFlexMode = Enum.UIFlexMode.Shrink
flex-noneFlexMode = Enum.UIFlexMode.None
growFlexMode = Enum.UIFlexMode.Grow
grow-0FlexMode = Enum.UIFlexMode.None
shrinkFlexMode = Enum.UIFlexMode.Shrink
shrink-0FlexMode = Enum.UIFlexMode.None
self-auto, self-start, self-center, self-end, self-stretchItemLineAlignment

Numbered forms like grow-2 or flex-2 don’t exist. basis-{value} is the same as w-{value}.

Child order

order-{n} sets LayoutOrder, which the list sorts by. Negative values (-order-2) work, as do order-first, order-last and order-none.

Under a divide-* parent, Vela rewrites each child’s LayoutOrder to its position. A component child must forward LayoutOrder to its root. See divide if separators land in the wrong place.

Grid and UIGridLayout

grid adds a UIGridLayout child. grid-cols-{n} (1–12) sets the number of columns, and grid-rows-{n} the number of rows.

The grid sizes its own cells, so a w-* on a cell does nothing. The column count sets the width:

grid grid-cols-2 gap-2.5
<uigridlayout FillDirectionMaxCells={2} CellSize={new UDim2(0.5, -5, 0, 100)} CellPadding={UDim2.fromOffset(10, 10)} />

Rows stay 100px tall until you set auto-rows-* (or auto-cols-* under grid-rows-*). They use the spacing scale, so auto-rows-24 is a 96px row.

gap-* sets CellPadding, and responsive gaps work: grid grid-cols-3 md:gap-4. Spans like col-span-* and row-span-* report no-roblox-equivalent. More grid edge cases are in the utilities reference.

Padding and UIPadding

Padding classes go into one UIPadding child. They work as in Tailwind: p-* sets all four sides, px-* and py-* set one axis, and pt-*, pr-*, pb-* and pl-* set one side.

Margins are built, not native

Roblox has no margins, so Vela builds one. It wraps the element in a clear frame padded by the margin.

ClassEffect
m-*, mx-*, my-*, mt-*, mr-*, mb-*, ml-*wraps the element in a margin frame
-mt-*, -ml-*shifts Position instead of wrapping
-mr-*, -mb-*unsupported-negative-margin
mx-auto, my-autocenters with AnchorPoint and Position, no wrapper

Any margin moves the element onto the runtime path, even in a plain string. m-0 and other zero margins are the exception.

Transitions and variants still work: m-4 w-20 transition-all hover:w-40 animates, and mt-2 hover:mt-4 applies.

The spacing value grammar

Padding, margin, gap, min/max and size offsets all read numbers the same way:

  1. If the key is in theme.spacing, Vela uses that value.
  2. Otherwise the key must be a non-negative multiple of 0.5, and Vela multiplies it by 4.

So p-1.5 is 6px and p-40 is 160px. p-0.25 reports unknown-theme-key. A leading sign is rejected.

The default theme has only one spacing key, so almost every number goes through step 2. To add named keys, see Theming.

Sizing and Size

w-*, h-* and size-* set the element’s Size. Each axis accepts:

  • px: exactly 1 pixel.
  • full: 100% of the parent.
  • A fraction, like w-1/2. Only the fractions in the table below work.
  • A spacing number, like w-40 (160px).
DenominatorAccepted numerators
/21
/31, 2
/41, 3
/51, 2, 3, 4
/61, 5
/121 through 11

Write fractions in lowest terms. w-2/4 reports unknown-theme-key. Use w-1/2.

Automatic sizing

fit and auto set AutomaticSize instead of Size:

ClassProperty
w-fit, w-autoAutomaticSize = Enum.AutomaticSize.X
h-fit, h-autoAutomaticSize = Enum.AutomaticSize.Y
size-fit, size-autoAutomaticSize = Enum.AutomaticSize.XY
w-fit h-fitAutomaticSize = Enum.AutomaticSize.XY

What gets emitted

Width and height merge into one Size, including under variants like md:w-32 md:h-32:

Merged into one Size
<frame className="w-full h-12" />
// Size = UDim2.new(1, 0, 0, 48)
<frame className="w-1/2 h-1/2" />
// Size = UDim2.fromScale(0.5, 0.5)
<frame className="w-40 h-8" />
// Size = UDim2.fromOffset(160, 32)

A custom spacing value with a scale part, like new UDim(0.5, 0), can’t be used for size. It reports unsupported-size-spacing-value.

Min and max size

min-w-*, max-w-*, min-h-* and max-h-* add a UISizeConstraint child. They take pixel values only, so max-w-1/2 doesn’t work.

An axis you don’t set has no limit: max-w-80 alone emits MaxSize = new Vector2(320, math.huge).

Position and anchor

Position classes set the element’s Position:

ClassEffect
left-*sets the X component
top-*sets the Y component
right-*sets the X component, measured from the far edge
bottom-*sets the Y component, measured from the far edge
inset-*sets both components
-left-*, -top-*, -inset-*the same, negated

They take the same values as sizing: px, full, fractions and spacing numbers.

right-* and bottom-* don’t move the anchor. The element’s top-left corner is still the point being placed. Add origin-* to place a different corner:

8px inside the parent's bottom-right corner
<frame className="right-2 bottom-2 origin-bottom-right w-24 h-8" />

Every Roblox element is already positioned relative to its parent, so absolute, relative and fixed report no-roblox-equivalent. Inside a flex or grid parent, the layout controls position and left-*/top-* have no effect.

origin-{key} sets AnchorPoint to a corner, an edge or the center. The nine keys are origin-center, origin-top, origin-bottom, origin-left, origin-right, and the four corners origin-top-left, origin-top-right, origin-bottom-left and origin-bottom-right. So origin-center is (0.5, 0.5) and origin-bottom-right is (1, 1). Anything else reports unsupported-anchor-value.

Translation

translate-x-* and translate-y-* shift the element. A fraction shifts by the element’s own size. A pixel value adds to Position. The usual CSS centering pattern works:

Dead center — AnchorPoint (0.5, 0.5), Position (0.5, 0.5) scale
<frame className="left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-96 h-40" />

mx-auto and my-auto do the same centering on one axis.

A fractional translate sets AnchorPoint, so don’t combine it with origin-*. The later class wins.

Aspect ratio

aspect-{key} adds a UIAspectRatioConstraint child. aspect-square is 1 and aspect-video is 16:9. For other ratios, use a bracket:

Arbitrary aspect ratios
<imagelabel className="w-full aspect-[16/9]" />
<frame className="w-40 aspect-[2.35]" />

aspect-auto reports unsupported-aspect-value.

Z-index

z-{value} sets ZIndex. The presets are z-0, z-10, z-20, z-30, z-40 and z-50. For other levels, use a whole number in brackets: z-[15].

InputDiagnostic
z-autounsupported-z-index-auto
-z-10unsupported-negative-z-index
z-[1.5]unsupported-arbitrary-z-index
z-5unsupported-z-index-value

Rotation and scale

rotate-N and -rotate-N set Rotation in degrees. The presets are 0, 1, 2, 3, 6, 12, 45, 90 and 180. For any other angle, use a bracket: rotate-[17deg]. Other unbracketed numbers report unsupported-rotation-value.

scale-N adds a UIScale child with Scale = N / 100. The values are 0, 50, 75, 90, 95, 100, 105, 110, 125 and 150, so scale-105 is 1.05. Other values, brackets included, report unsupported-scale-value. Scaling is uniform, so there is no scale-x-* or scale-y-*.

Visibility and clipping

hidden sets Visible = false. visible sets Visible = true.

overflow-hidden and overflow-clip set ClipsDescendants = true. overflow-visible sets it to false. Other values report unsupported-overflow-value. To scroll, use a scrollingframe element.

What layout still cannot express

  • Grid spans and flow: col-span-*, row-span-*, grid-flow-*.
  • CSS positioning: absolute, relative, fixed, sticky, float, clear.
  • Per-axis gaps: gap-x-* and gap-y-*. These report unknown-theme-key, not an unknown-class warning.
  • Reversed direction: flex-row-reverse, flex-col-reverse. Use order-*.

See also