UDim and UDim2 types, which combine scale (relative) and offset (absolute) components.
UDim structure
Roblox usesUDim for single-axis values and UDim2 for two-axis values:
Absolute units
Pixels
input.css
output.luau
| CSS | UDim Equivalent | Notes |
|---|---|---|
200px | UDim.new(0, 200) | Absolute offset |
Rem units
rem units use a 16px base (same as most browsers):input.css
output.luau
| CSS | Calculation | UDim Equivalent |
|---|---|---|
1rem | 1 × 16 = 16px | UDim.new(0, 16) |
1.5rem | 1.5 × 16 = 24px | UDim.new(0, 24) |
0.5rem | 0.5 × 16 = 8px | UDim.new(0, 8) |
Em units
Em units are approximated as rem (16px base) since Roblox doesn’t have cascading font sizes:input.css
output.luau
Relative units
Percentages
input.css
output.luau
| CSS | UDim Equivalent | Notes |
|---|---|---|
100% | UDim.new(1, 0) | Scale = 1 (full size) |
50% | UDim.new(0.5, 0) | Scale = 0.5 (half size) |
25% | UDim.new(0.25, 0) | Scale = 0.25 (quarter size) |
Viewport units
vw (viewport width) and vh (viewport height) are treated as percentages:input.css
output.luau
| CSS | Conversion | UDim Equivalent |
|---|---|---|
100vw | 100 ÷ 100 = 1 | UDim.new(1, 0) |
50vw | 50 ÷ 100 = 0.5 | UDim.new(0.5, 0) |
25vh | 25 ÷ 100 = 0.25 | UDim.new(0.25, 0) |
Mixed units
You can mix relative and absolute units usingcalc() (though calc expressions themselves aren’t supported, you can achieve the same with separate properties):
input.css
output.luau
Auto sizing
Theauto keyword maps to Roblox’s AutomaticSize property:
input.css
output.luau
| CSS | Roblox Property | Value |
|---|---|---|
width: auto only | AutomaticSize | Enum.AutomaticSize.X |
height: auto only | AutomaticSize | Enum.AutomaticSize.Y |
| Both auto | AutomaticSize | Enum.AutomaticSize.XY |
Unsupported units
These CSS units are not supported and will emit warnings:| CSS Unit | Reason |
|---|---|
cm, mm, in, pt, pc | Physical units have no meaning in screen-based UI |
ch, ex | Font-relative units not supported |
vmin, vmax | No Roblox equivalent |
calc() | Expression evaluation not supported |
Zero values
Unitless zero is valid in CSS and maps to UDim zero:input.css
output.luau
Complete examples
Example 1: Centered box
input.css
output.luau
Example 2: Responsive container
input.css
output.luau
Example 3: Offset from corner
input.css
output.luau
Unit conversion reference
| CSS | Scale | Offset | UDim |
|---|---|---|---|
100px | 0 | 100 | UDim.new(0, 100) |
50% | 0.5 | 0 | UDim.new(0.5, 0) |
1rem | 0 | 16 | UDim.new(0, 16) |
2em | 0 | 32 | UDim.new(0, 32) |
75vw | 0.75 | 0 | UDim.new(0.75, 0) |
0 | 0 | 0 | UDim.new(0, 0) |
Best practices
- Use pixels for fixed sizes: Buttons, icons, borders
- Use percentages for layouts: Columns, responsive containers
- Use rem for spacing: Consistent padding and gaps across your UI
- Avoid mixing units in calc(): Not supported; use separate properties instead
- Test with different screen sizes: Remember that scale is relative to parent size