Skip to content

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

OptionDefaultWhat 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
themesbuilt from baseColor and primaryYour own set of themes, replacing the built in ones
colorsnoneNamed colours: { hype = "$Yellow400" }
colorRecipesnoneYour own shades of every named colour, by name
primitivesLucy.Tokens.primitivesYour own primitives, replacing the whole set
densitiesLucy.Tokens.densitiesYour own densities, replacing the whole set
densityfollows the devicePins a density
styleParentReplicatedStorageWhere 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

KeyValueWriting it
themethe theme’s nameswitches 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.

TokenColoursLightDark
Backgroundthe page behind everythingWhitec-950
Foregroundtext on the backgroundc-950c-50
Card, CardForegroundpanels and their textWhite, c-950c-900, c-50
Popover, PopoverForegroundmenus, selects, tooltipsWhite, c-950c-900, c-50
Primarythe main action colourp-600 (or c-900)p-500 (or c-200)
PrimaryForegroundtext on Primaryon colouron colour
PrimaryHoverPrimary hoveredPrimary at 90%Primary at 90%
Secondary, SecondaryForeground, SecondaryHoverquieter buttonsc-100, c-900, 80%c-800, c-50, 80%
Muted, MutedForegroundsubdued surfaces and hint textc-100, c-500c-800, c-400
Accent, AccentForegroundhovered rows and itemsc-100, c-900c-800, c-50
Destructive, DestructiveForeground, DestructiveHoverdelete and dangerRed-600, on colour, 90%Red-400, on colour, 90%
Borderdividers and outlinesc-200White at 10%
Inputfield outlinesc-200White at 15%
Ringthe focus ringp-400 (or blue-500)p-300 (or blue-400)
Overlay, OverlayTransparencythe scrim behind modalsBlack, 0.5Black, 0.3
Success, Warning, Infostatus coloursGreen-600, Amber-500, Blue-600Green-500, Amber-400, Blue-500
SuccessForeground, WarningForeground, InfoForegroundtext on a status colouron colouron colour
DestructiveSubtle, SuccessSubtle, WarningSubtle, InfoSubtlea pale wash of the colour, for alertscolour at 10% over Cardcolour at 16% over Card
DestructiveSubtleForeground and the resttext on a washon colour, in the full colour’s hueon colour, in the full colour’s hue
OverlayFill, OverlayFillForeground, OverlayFillTransparencya translucent fill over a picture (Badge’s overlay) and its wordsWhite 85% opaque, base 950Black 85% opaque, White
MedalGold, MedalSilver, MedalBronzefirst, second and third place (Leaderboard)Amber-500, Slate-400, Orange-700Yellow-400, Slate-300, Orange-400
GradientSurfacea card deepening toward the background (Gradient)Card to Card mixed 60% with MutedCard to Background
GradientPrimarythe primary colour, lit at the top and deepening at the bottomPrimary mixed 25% with White to Primary mixed 20% with Blackthe 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.

TokenValue
<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, RadiusFull3, 6, 8, 10, 14 px, and fully round
Space0 to Space6, Space80 to 24 px in steps of 4, and 32 px
FontSans, FontSansMedium, FontSansSemibold, FontSansBoldNunito, for text
FontDisplayFredoka, for headings
StrokeThin, StrokeThick1 and 2 px
FocusRing3 px: the focus ring’s sharp edge
FocusFeather, FocusHalo6 and 10 px: the focus ring’s softer feather and fainter halo, reaching in from its edge
PanelShadow0: a Dialog or Sheet’s shadow, in px right and down (0 draws none)
PanelPlateOverlap14: 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)
PanelTitleEdge0: 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

Tokendefaulttouchtv
ControlSm, ControlMd, ControlLg32, 36, 4040, 44, 4844, 52, 60
ControlXl485672
ControlIcon36 square44 square52 square
TextXs to Text4xl12, 14, 16, 18, 20, 24, 30, 36same as default14, 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

MemberWhat 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
themesthe themes an App gets when it picks no colours: themesFor("mauve", { primary = "violet" })
defaultPrimary"violet", the primary an App uses when it names none
spectrumthe 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, themesLucy’s own sets, to copy and change
basesthe 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

MethodWhat 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, DensityChangedsignals, fired with the new name
MetricsChangedsignal, fired when control heights change for text size

Rules

A rule is a table:

FieldWhat it is
selectorwhich instances: a class (TextLabel), a tag (.shop-price), states (:Hover, :Press), children (> .x) and descendants (>> .x)
prioritywhich rule wins when several in the same layer match; higher wins, and at equal priority the rule added later
propertiesproperty values; $Name for tokens
transitionsoptional TweenInfo per property, for smooth changes
scopedfor 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.