Theming
How Lucy’s themes are put together, and everything you can set. For a walk through, see Add a theme.
Lucy styles with Universal Styling. The tokens live as attributes on style sheets; components and your own rules point at them with $Name. Switching theme or density points the sheets at another set of values, so every linked gui restyles at once.
Folder <namePrefix>Styles (ReplicatedStorage)
├─ Tokens primitives: palette, radius, space, fonts, stroke
├─ Theme_light, _dark... colour tokens, one sheet per theme
├─ Density_default, _touch, _tv control heights and type scale
├─ Values the active theme and density (switching re-points these)
├─ Lucy Lucy's base and component rules, all of them from the start
├─ Game your rules
├─ Fixed Lucy's rules for what a component is: an untinted icon keeps its own
│ colours, a gradient's host stays white under it
├─ Design live rules, added and removed while the game runs; every gui links here
└─ Lucy_0, Game_40... a layer's rules of one priority, one sheet each
The rule sheets are layers: each derives the one below, and a sheet’s own rules beat every rule below it, whatever their priority. So your rules beat Lucy’s looks without a priority above Lucy’s, Lucy’s few fixed rules (marked fixed = true) beat yours, and a live rule beats all. Lucy’s own rules are all in place when the app is made, so nothing is added to the styles while a player plays.
Inside Lucy, Game and Fixed, each priority’s rules are a sheet of their own, which the layer derives lowest priority first. They apply exactly as one sheet would, but adding a rule only pays for the rules of its own priority, so start-up stays quick with thousands of rules. app.theme:rulesOf("game") lists a layer’s rules in the order they apply.
App options
| Option | Default | What it does |
|---|---|---|
theme | "dark" | The theme to start in |
baseColor | "mauve" | Base colour for the built in light and dark themes |
primary | "violet" | Palette hue that tints Primary and Ring. "none" gives a black and white look: Primary in the base colour, Ring in blue |
themes | built from baseColor and primary | Your own set of themes, replacing the built in ones |
colors | none | Named colours: { hype = "$Yellow400" } |
colorRecipes | none | Your own shades of every named colour, by name |
primitives | Lucy.Tokens.primitives | Your own primitives, replacing the whole set |
densities | Lucy.Tokens.densities | Your own densities, replacing the whole set |
density | follows the device | Pins a density |
styleParent | ReplicatedStorage | Where the style sheets folder goes |
Base colours: zinc, slate, gray, neutral, stone, mauve, olive, mist, taupe. Primary hues: red, orange, amber, yellow, lime, green, emerald, teal, cyan, sky, blue, indigo, violet, purple, fuchsia, pink, rose (the base colours work too).
State keys
| Key | Value | Writing it |
|---|---|---|
theme | the theme’s name | switches the theme; an unknown name warns and is put back |
density | "default", "touch" or "tv" | switches the density; Lucy also sets it when the device changes, unless density is pinned |
Colour tokens
Every theme has these. The light and dark columns show the built in themes for a base colour c and primary hue p (c-950 is the base colour’s 950 shade). With primary = "none", the p values fall back to the base colour shades shown.
| Token | Colours | Light | Dark |
|---|---|---|---|
Background | the page behind everything | White | c-950 |
Foreground | text on the background | c-950 | c-50 |
Card, CardForeground | panels and their text | White, c-950 | c-900, c-50 |
Popover, PopoverForeground | menus, selects, tooltips | White, c-950 | c-900, c-50 |
Primary | the main action colour | p-600 (or c-900) | p-500 (or c-200) |
PrimaryForeground | text on Primary | on colour | on colour |
PrimaryHover | Primary hovered | Primary at 90% | Primary at 90% |
Secondary, SecondaryForeground, SecondaryHover | quieter buttons | c-100, c-900, 80% | c-800, c-50, 80% |
Muted, MutedForeground | subdued surfaces and hint text | c-100, c-500 | c-800, c-400 |
Accent, AccentForeground | hovered rows and items | c-100, c-900 | c-800, c-50 |
Destructive, DestructiveForeground, DestructiveHover | delete and danger | Red-600, on colour, 90% | Red-400, on colour, 90% |
Border | dividers and outlines | c-200 | White at 10% |
Input | field outlines | c-200 | White at 15% |
Ring | the focus ring | p-400 (or blue-500) | p-300 (or blue-400) |
Overlay, OverlayTransparency | the scrim behind modals | Black, 0.5 | Black, 0.3 |
Success, Warning, Info | status colours | Green-600, Amber-500, Blue-600 | Green-500, Amber-400, Blue-500 |
SuccessForeground, WarningForeground, InfoForeground | text on a status colour | on colour | on colour |
DestructiveSubtle, SuccessSubtle, WarningSubtle, InfoSubtle | a pale wash of the colour, for alerts | colour at 10% over Card | colour at 16% over Card |
DestructiveSubtleForeground and the rest | text on a wash | on colour, in the full colour’s hue | on colour, in the full colour’s hue |
OverlayFill, OverlayFillForeground, OverlayFillTransparency | a translucent fill over a picture (Badge’s overlay) and its words | White 85% opaque, base 950 | Black 85% opaque, White |
MedalGold, MedalSilver, MedalBronze | first, second and third place (Leaderboard) | Amber-500, Slate-400, Orange-700 | Yellow-400, Slate-300, Orange-400 |
GradientSurface | a card deepening toward the background (Gradient) | Card to Card mixed 60% with Muted | Card to Background |
GradientPrimary | the primary colour, lit at the top and deepening at the bottom | Primary mixed 25% with White to Primary mixed 20% with Black | the same |
On colour means text in the fill’s own colour: its hue taken to its darkest (like red-950 on red) or lightest (like red-200), whichever has more contrast with the fill, as WCAG 2 measures it. If that is under 4.5:1 (level AA for body text), it is made lighter or darker in OKLCH, keeping its hue, until it reaches it. Text on a fill reads as part of the fill rather than black or white stuck on top, and stays readable with any base colour, primary hue or theme of your own built with onColor. On a strong mid colour, such as red-600, only near white reaches 4.5:1, so the light shade can come out almost white. A grey fill gets grey text.
“At 90%” means composited over the background, as a browser would: a Color3 has no transparency, so Lucy works the blend out when the theme is built.
Primitives
The same in every theme.
| Token | Value |
|---|---|
<Hue><Shade> | every palette colour, such as Violet500 or Zinc950; shades 50, 100, 200 to 900, 950 (Colours shows them all) |
White, Black | |
RadiusXs, RadiusSm, RadiusMd, RadiusLg, RadiusXl, RadiusFull | 3, 6, 8, 10, 14 px, and fully round |
Space0 to Space6, Space8 | 0 to 24 px in steps of 4, and 32 px |
FontSans, FontSansMedium, FontSansSemibold, FontSansBold | Nunito, for text |
FontDisplay | Fredoka, for headings |
StrokeThin, StrokeThick | 1 and 2 px |
FocusRing | 3 px: the focus ring’s sharp edge |
FocusFeather, FocusHalo | 6 and 10 px: the focus ring’s softer feather and fainter halo, reaching in from its edge |
PanelShadow | 0: a Dialog or Sheet’s shadow, in px right and down (0 draws none) |
PanelPlateOverlap | 14: how far a title on the edge comes down over its panel, in px (the panel’s content starts that much lower, so it clears the title) |
PanelTitleEdge | 0: where dialog and sheet titles go when a panel does not say (1 puts every one on a plate on the top edge) |
Every border and ring is drawn inside its element’s edge, so a border never makes an element bigger than its size, and a scroll area or a tight row never cuts one off. A rule of your own that draws a border on a ::UIStroke should do the same with BorderStrokePosition = Enum.BorderStrokePosition.Inner.
Densities
| Token | default | touch | tv |
|---|---|---|---|
ControlSm, ControlMd, ControlLg | 32, 36, 40 | 40, 44, 48 | 44, 52, 60 |
ControlXl | 48 | 56 | 72 |
ControlIcon | 36 square | 44 square | 52 square |
TextXs to Text4xl | 12, 14, 16, 18, 20, 24, 30, 36 | same as default | 14, 16, 18, 22, 24, 28, 34, 42 |
Control tokens are UDim2 heights; text tokens are TextSize numbers. When a player picks a larger text size in the Roblox menu, the control heights grow to fit; see Accessibility.
Lucy.Tokens
| Member | What it is |
|---|---|
themesFor(base, { primary }) | the built in { light, dark } themes for a base colour and primary hue; with no primary here, the black and white look |
themes | the themes an App gets when it picks no colours: themesFor("mauve", { primary = "violet" }) |
defaultPrimary | "violet", the primary an App uses when it names none |
spectrum | the colours of Lucy the mascot, { magenta, orchid, sky }, ready to pass as named colours: colors = Lucy.Tokens.spectrum |
oklch(L, C, H) | a colour from OKLCH lightness (0 to 1), chroma and hue (degrees) |
over(fg, bg, alpha) | fg at alpha over bg, as a theme value; worked out per theme |
mix(a, b, t) | an even mix of two tokens in Oklab; t 0 gives a, 1 gives b |
adjust(a, { l?, c?, h? }) | a moved in OKLCH: the numbers added to its lightness (0 to 1), chroma and hue (degrees), so a dimmer shade keeps its hue ({ l = -0.2 }); worked out per theme |
onColor(fill, { min?, tint? }) | text for fill in its own colour, at its darkest or lightest, readable to min (4.5 by default); tint takes the hue from another token, for a pale wash; worked out per theme |
gradient(stops) | a gradient, as a theme value: colours from first to last, or { position, colour } pairs; each a token, a Color3 or a blend; worked out per theme (Gradient) |
readable(fill, a, b, min?) | text for fill: a or b, whichever reads better, moved in lightness if needed to reach min (4.5 by default); worked out per theme |
name(hue, shade) | a palette token’s name: name("violet", 500) is "Violet500" |
primitives, densities, themes | Lucy’s own sets, to copy and change |
bases | the base colour names |
Lucy.Palette has every colour as OKLCH values, and Palette.hues and Palette.shades list them.
Lucy.Oklab does the colour maths: Oklab.contrast(a, b) gives the WCAG 2 contrast ratio between two colours (1 to 21), Oklab.luminance(color) their relative luminance, and Oklab.onColor(fill, min?, tint?) and Oklab.readable(fill, a, b, min?) the same choices as Tokens.onColor and Tokens.readable for plain colours.
A theme of your own can work out its text the same way:
local themes = Lucy.Tokens.themesFor("zinc", { primary = "fuchsia" })
themes.dark.Primary = "$Fuchsia300"
themes.dark.PrimaryForeground = Lucy.Tokens.onColor("$Primary")
app.theme
| Method | What it does |
|---|---|
get(), set(name) | the current theme; set errors on an unknown name (setting app.state warns instead) |
names() | every theme’s name, sorted |
getDensity(), setDensity(name) | the current density |
setTextGrowth(grow) | grows ControlSm, ControlMd and ControlLg by grow(size) of their text size, in every density; nil takes it off. The app sets it from the player’s text size |
resolve(token) | the value a token has right now, through aliases: resolve("Primary") is a Color3 |
addRules(key, rules, { layer? }) | adds style rules under a key, in your Game layer; { layer = "live" } for rules you add and remove while playing (a setting switched on); does nothing if the key is there |
removeRules(key), hasRules(key) | takes a key’s rules out; checks for them |
rulesOf(layer) | a layer’s rules ("lucy", "game", "fixed" or "live") in the order they apply |
link(gui) | styles a ScreenGui you made yourself (scenes and portals are linked already) |
Changed, DensityChanged | signals, fired with the new name |
MetricsChanged | signal, fired when control heights change for text size |
Rules
A rule is a table:
| Field | What it is |
|---|---|
selector | which instances: a class (TextLabel), a tag (.shop-price), states (:Hover, :Press), children (> .x) and descendants (>> .x) |
priority | which rule wins when several in the same layer match; higher wins, and at equal priority the rule added later |
properties | property values; $Name for tokens |
transitions | optional TweenInfo per property, for smooth changes |
scoped | for a rule in $Color: only inside a coloured container (Named colours) |
Priority only orders rules within a layer. Your layer is above Lucy’s, so your rules need no priority to beat Lucy’s: state what a thing looks like, and for its states (:Hover, .ui-disabled, .ui-focus-visible) add a rule of its own with a higher priority than your base rule. Lucy’s layer uses reset -100, base 0, variant and size 10, state 20, disabled 30 and focus ring 100. Roblox has no CSS specificity: a more specific selector does not win by itself.
Your own components declare their rules when their module loads, as Lucy’s do: Component.define(spec) at the end of the module, so an app made afterwards has them from the start. A component that does not, adds them on its first mount (and warns in Studio).
Components carry tags you can match too: ui-<component> (such as ui-button), ui-<component>-<key>-<value> for variants (ui-button-variant-outline), and the flags ui-disabled, ui-checked, ui-selected, ui-open, ui-focused and ui-focus-visible.
A component that holds content (a badge, a button, a tab, an option) gives what is in its slot its colours with generated rules. To colour one your own way, add your rule with Slot.foreground, so the words and icons inside change with it: a plain TextColor3 rule on the root only reaches the root’s own text.
Styles apply a few frames after a change. Read what an instance shows with instance:GetStyled(property); the plain property gives the unstyled value.
Named colours
Name the colours your game uses, and Lucy works out their shades and colours its components with them wherever you say:
local app = Lucy.App.new({
colors = { hype = "$Yellow400", premium = "$Amber500", ["genre-house"] = "$Cyan400" },
})
Each colour gets a token (Hype, GenreHouse) and these shades of it, worked out as Primary’s are: HypeHover, HypeForeground (text on it), HypeSoft (a quiet wash of it on a card), HypeMutedForeground (quiet text on that wash), HypeBorder and HypeShadow (a deep shade, for a hard shadow). Primary gets the same shades. A token your theme sets itself is kept.
Your own shades are recipes: a function of the colour’s token and a way to name its other shades, made for every colour and for Primary.
colorRecipes = {
Glow = function(colour) return Lucy.Tokens.mix("$Background", colour, 0.24) end,
GlowText = function(_, shade) return Lucy.Tokens.readable(shade("Glow"), "$White", "$Black") end,
}
To colour part of the UI, give a component color, or colour any container:
Lucy.Sheet.new({ title = "THE LAB", color = "premium", children = { ... } })
Lucy.color(card, "hype") -- a name, a ref or getter of one, or nil; returns stop()
-- or as a prop, stopped with the element's bindings
Lucy.new("TextLabel", { Tags = { "shop-price" }, [Lucy.color] = tone })
Lucy.hydrate(card)({ [Lucy.color] = "hype" })
Lucy’s components inside take the colour wherever they would use Primary: filled and outline buttons, the picked toggle and tab, switches, checkboxes, radios, progress, sliders, spinners and badges. The nearest coloured container wins, as a CSS variable does: a hype card in a premium sheet is hype inside, premium round it. What is added later takes the colour as it arrives.
Write your own rules in $Color, $ColorHover, $ColorForeground, $ColorSoft or any shade, yours included ($ColorGlow). Lucy compiles them: once with Primary’s tokens, for where no colour is set, and once per colour. scoped = true keeps a rule to coloured containers:
app.theme:addRules("shopCards", {
{ selector = ".shop-card::UIStroke", scoped = true, properties = { Color = "$ColorBorder" } },
{ selector = ".shop-card >> .shop-price", properties = { TextColor3 = "$Color" } },
})
The colour goes on the first part of each selector (.shop-card here): a coloured container tags itself and every element in it that has a tag of its own, as ui-color-<name>, and the compiled rules match that.
A scoped rule with no $Color holds in any colour, so it is compiled once, on ui-colored, which every coloured element also has:
{ selector = ".shop-tab:Hover", scoped = true, properties = { TextColor3 = "$White" } }
-- one rule: .shop-tab.ui-colored:Hover
Roblox’s tokens cannot be scoped below a ScreenGui, which is why a colour is a tag on the elements and its rules are compiled per colour.
Colours that colour only some things
Each colour gets its own copy of every rule written in $Color, Lucy’s and yours. A game with many colours has many copies, and every copy is a rule the engine checks new elements against: Dance Lab’s 38 colours made 3,572 of its 4,904 rules, and a panel’s first open paid for them. Most colours are only ever put on a few kinds of thing, so say which:
colors = {
hype = "$Yellow400", -- everything, as before
["genre-house"] = { "$Orange500", on = { "shopCards", "badge" } }, -- only these groups
}
on names groups of rules: a component’s kind (button, badge, progress, toggle, switch…) or the key you gave theme:addRules. The colour is then compiled only for those groups’ $Color rules; elsewhere an element in that colour shows Primary’s look. To find what a colour’s groups leave out, check a screen in Studio:
for _, miss in app.theme:uncoveredColors(playerGui) do
print(miss.color, miss.group, miss.instance:GetFullName())
end
It lists every element in a colour that a group’s $Color rule would style if the colour listed that group.