Skip to main content
This example demonstrates core CSS-to-Roblox mappings including colors, sizing, typography, and border radius.

Example overview

We’ll create a styled card component with:
  • Background color and transparency
  • Fixed dimensions
  • Rounded corners using border-radius
  • Text styling with custom font and size
  • Padding using UIPadding
1

Write the CSS

Create a CSS file with basic styling properties:
styles.css
.card {
  background-color: #ffffff;
  width: 300px;
  height: 200px;
  border-radius: 12px;
  padding: 20px;
}

.card > span {
  color: #1a1a2e;
  font-size: 18px;
  font-family: "GothamSSm";
  font-weight: 600;
}
2

Compile to Luau

Run the rbx-css compiler:
rbx-css compile styles.css -o StyleSheet.luau
3

Review the output

The generated Luau code creates a StyleSheet with mapped properties:
StyleSheet.luau
-- Auto-generated by rbx-css
-- Source: styles.css

local function createStyleSheet()
  local sheet = Instance.new("StyleSheet")
  sheet.Name = "StyleSheet"

  -- Rule: .card
  do
    local rule = Instance.new("StyleRule")
    rule.Selector = ".card"
    rule.Parent = sheet
    rule:SetProperties({
      BackgroundColor3 = Color3.fromRGB(255, 255, 255),
      Size = UDim2.new(0, 300, 0, 200),
    })
  end

  -- Rule: .card::UICorner
  do
    local rule = Instance.new("StyleRule")
    rule.Selector = ".card::UICorner"
    rule.Parent = sheet
    rule:SetProperty("CornerRadius", UDim.new(0, 12))
  end

  -- Rule: .card::UIPadding
  do
    local rule = Instance.new("StyleRule")
    rule.Selector = ".card::UIPadding"
    rule.Parent = sheet
    rule:SetProperties({
      PaddingTop = UDim.new(0, 20),
      PaddingBottom = UDim.new(0, 20),
      PaddingLeft = UDim.new(0, 20),
      PaddingRight = UDim.new(0, 20),
    })
  end

  -- Rule: .card > TextLabel (from 'span')
  do
    local rule = Instance.new("StyleRule")
    rule.Selector = ".card > TextLabel"
    rule.Parent = sheet
    rule:SetProperties({
      TextColor3 = Color3.fromRGB(26, 26, 46),
      TextSize = 18,
      FontFace = Font.new(
        "rbxasset://fonts/families/GothamSSm.json",
        Enum.FontWeight.SemiBold
      ),
    })
  end

  return sheet
end

return createStyleSheet

Key mappings

Colors

background-color: #ffffffBackgroundColor3 = Color3.fromRGB(255, 255, 255) All CSS color formats (hex, rgb, hsl, named colors) are converted to Roblox Color3 values.

Sizing

width: 300px; height: 200pxSize = UDim2.new(0, 300, 0, 200) Pixel values map to UDim offset values. Scale can be used with percentages:
width: 50%; /* → UDim2.new(0.5, 0, ...) */

Border radius

border-radius: 12px::UICorner pseudo-instance with CornerRadius = UDim.new(0, 12) The compiler automatically generates a separate UICorner rule that the StyleSheet system applies.

Padding

padding: 20px::UIPadding pseudo-instance with all sides set to UDim.new(0, 20) Supports all CSS padding shorthand formats:
  • padding: 10px — all sides
  • padding: 10px 20px — vertical | horizontal
  • padding: 10px 20px 30px 40px — top | right | bottom | left

Typography

  • color: #1a1a2eTextColor3
  • font-size: 18pxTextSize = 18
  • font-family: "GothamSSm"FontFace with GothamSSm font family
  • font-weight: 600Enum.FontWeight.SemiBold

Element mapping

spanTextLabel in the selector HTML elements are automatically mapped to their Roblox equivalents. See the full mapping table in the CSS mapping reference.

Build docs developers (and LLMs) love