Skip to main content
rbx-css supports all standard CSS color formats and converts them to Roblox Color3 values with optional transparency.

RGB colors

Hex notation

input.css
.box {
  background-color: #335fff;
  color: #fff;              /* shorthand */
  border-color: #33f;       /* shorthand expands to #3333ff */
}
output.luau
rule:SetProperty("BackgroundColor3", Color3.fromRGB(51, 95, 255))
rule:SetProperty("TextColor3", Color3.fromRGB(255, 255, 255))
rule:SetProperty("Color", Color3.fromRGB(51, 51, 255))

RGB function

input.css
.box {
  background-color: rgb(51, 95, 255);
  color: rgb(255, 255, 255);
}
output.luau
rule:SetProperty("BackgroundColor3", Color3.fromRGB(51, 95, 255))
rule:SetProperty("TextColor3", Color3.fromRGB(255, 255, 255))

RGBA function (with transparency)

input.css
.box {
  background-color: rgba(51, 95, 255, 0.8);
  color: rgba(255, 255, 255, 0.7);
}
output.luau
-- Alpha channel maps to transparency (inverted)
rule:SetProperties({
  BackgroundColor3 = Color3.fromRGB(51, 95, 255),
  BackgroundTransparency = 0.2,  -- 1 - 0.8
})

rule:SetProperties({
  TextColor3 = Color3.fromRGB(255, 255, 255),
  TextTransparency = 0.3,  -- 1 - 0.7
})
CSS alpha values (0-1, where 1 is opaque) are inverted to Roblox transparency (0-1, where 0 is opaque). An alpha of 0.8 becomes transparency of 0.2.

Modern color spaces

OKLCH (Oklab cylindrical)

input.css
.box {
  background-color: oklch(0.65 0.15 250);
  /* Lightness, Chroma, Hue */
}
output.luau
-- Converted to RGB internally
rule:SetProperty("BackgroundColor3", Color3.fromRGB(r, g, b))

OKLAB (Oklab rectangular)

input.css
.box {
  background-color: oklab(0.65 -0.1 -0.1);
  /* Lightness, a, b */
}
output.luau
-- Converted to RGB internally
rule:SetProperty("BackgroundColor3", Color3.fromRGB(r, g, b))

LAB (CIE Lab)

input.css
.box {
  background-color: lab(50% 40 -20);
  /* Lightness, a, b */
}
output.luau
-- Converted to RGB using D65 white point
rule:SetProperty("BackgroundColor3", Color3.fromRGB(r, g, b))

LCH (CIE LCH)

input.css
.box {
  background-color: lch(50% 40 200);
  /* Lightness, Chroma, Hue */
}
output.luau
-- Converted to RGB using D65 white point
rule:SetProperty("BackgroundColor3", Color3.fromRGB(r, g, b))

Named colors

A subset of CSS named colors are supported:
input.css
.box {
  background-color: white;
  color: black;
  border-color: red;
}
output.luau
rule:SetProperty("BackgroundColor3", Color3.fromRGB(255, 255, 255))
rule:SetProperty("TextColor3", Color3.fromRGB(0, 0, 0))
rule:SetProperty("Color", Color3.fromRGB(255, 0, 0))

Supported named colors

NameRGB Value
white(255, 255, 255)
black(0, 0, 0)
red(255, 0, 0)
green(0, 128, 0)
blue(0, 0, 255)
yellow(255, 255, 0)
cyan(0, 255, 255)
magenta(255, 0, 255)
orange(255, 165, 0)
purple(128, 0, 128)
pink(255, 192, 203)
gray, grey(128, 128, 128)

Transparent keyword

input.css
.box {
  background-color: transparent;
  /* or */
  background: transparent;
}
output.luau
rule:SetProperty("BackgroundTransparency", 1)

HSL colors

While lightningcss (the parser rbx-css uses) converts most color formats internally, HSL is converted to RGB:
input.css
.box {
  background-color: hsl(220, 100%, 60%);
  color: hsla(220, 100%, 60%, 0.5);
}
output.luau
-- Converted to RGB
rule:SetProperty("BackgroundColor3", Color3.fromRGB(r, g, b))
rule:SetProperties({
  TextColor3 = Color3.fromRGB(r, g, b),
  TextTransparency = 0.5,
})

Color properties

Background color

input.css
.box {
  background-color: #335fff;
  /* or */
  background: #335fff;
}
output.luau
rule:SetProperty("BackgroundColor3", Color3.fromRGB(51, 95, 255))

Text color

input.css
.text {
  color: white;
}
output.luau
rule:SetProperty("TextColor3", Color3.fromRGB(255, 255, 255))

Border color

input.css
.box {
  border: 2px solid #333;
  /* or */
  border-color: #333;
}
output.luau
-- Creates UIStroke pseudo-instance
strokeRule:SetProperty("Color", Color3.fromRGB(51, 51, 51))

Transparency mapping

Alpha channels in CSS colors map to Roblox transparency properties:
CSS PropertyColor PropertyTransparency Property
background-colorBackgroundColor3BackgroundTransparency
colorTextColor3TextTransparency
border-color (UIStroke)ColorTransparency

Example with transparency

input.css
.card {
  background-color: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.2);
}
output.luau
-- Main rule
rule:SetProperties({
  BackgroundColor3 = Color3.fromRGB(255, 255, 255),
  BackgroundTransparency = 0.9,  -- 1 - 0.1
  TextColor3 = Color3.fromRGB(255, 255, 255),
  TextTransparency = 0.1,  -- 1 - 0.9
})

-- UIStroke rule for border
strokeRule:SetProperties({
  Color = Color3.fromRGB(255, 255, 255),
  Transparency = 0.8,  -- 1 - 0.2
  Thickness = 1,
})

Gradients

Gradients use multiple colors and create UIGradient pseudo-instances. See Pseudo-instances - UIGradient.
input.css
.gradient {
  background: linear-gradient(90deg, #ff0099 0%, #ffcc00 100%);
}
output.luau
-- Creates UIGradient pseudo-instance
gradientRule:SetProperty("Color", ColorSequence.new({
  ColorSequenceKeypoint.new(0, Color3.fromRGB(255, 0, 153)),
  ColorSequenceKeypoint.new(1, Color3.fromRGB(255, 204, 0)),
}))

CSS variables (color tokens)

Color tokens from CSS custom properties are automatically inferred:
input.css
:root {
  --primary: #335fff;
  --text: rgba(255, 255, 255, 0.9);
}

.button {
  background-color: var(--primary);
  color: var(--text);
}
output.luau
-- Token attributes (type inferred as Color3)
sheet:SetAttribute("primary", Color3.fromRGB(51, 95, 255))
sheet:SetAttribute("text", Color3.fromRGB(255, 255, 255))
-- Note: transparency from token alpha is applied at rule level

-- Rule using tokens
rule:SetProperty("BackgroundColor3", "$primary")
rule:SetProperty("TextColor3", "$text")

Color gamut and clamping

When converting from modern color spaces (OKLCH, LAB, LCH), colors outside the sRGB gamut are clamped to valid RGB values:
input.css
.vivid {
  /* This might produce colors outside sRGB gamut */
  background-color: oklch(0.8 0.4 250);
}
output.luau
-- Out-of-gamut values are clamped to 0-255 range
rule:SetProperty("BackgroundColor3", Color3.fromRGB(
  clamp(r, 0, 255),
  clamp(g, 0, 255),
  clamp(b, 0, 255)
))

Unsupported color features

CSS FeatureReason
currentColorNo cascading color value in Roblox
color-mix()Not supported by parser
CSS Color Level 5 featuresNot yet widely supported

Color conversion accuracy

rbx-css uses standard color space conversion algorithms:
  • OKLCH/OKLAB: Björn Ottosson’s Oklab color space
  • LAB/LCH: CIE Lab with D65 illuminant
  • RGB gamma correction: sRGB gamma correction (2.4)
Colors are rounded to the nearest integer (0-255) for Roblox Color3.fromRGB().

Build docs developers (and LLMs) love