Skip to content

Color tokens ​

Theme is a flat set of 19 color tokens. Components read tokens through ui.visuals() or theme::current(ctx); they never define a literal color.

GitHub Light ​

TokenValuePaints
backgroundbackground#ffffffWindow, editor, panels (panel_fill)
surfacesurface#f6f8faMenus, dialogs, sidebar, tab strip (window_fill)
surface_raisedsurface_raised#ffffffSecond raised surface (toasts)
sunkensunken#f6f8faText fields, steppers, segmented (extreme_bg_color)
texttext#1f2328Primary text
text_mutedtext_muted#596069Hints, descriptions, inactive tabs
accentaccent#0969daBrand accent, active state
accent_textaccent_text#ffffffText on the accent
borderborder#d1d9e0Borders and separators
selectionselection#b6d7ffSelected rows, segments, primary buttons
hoverhover#eaeef2Row and icon hover
dangerdanger#cf222eErrors, destructive actions
warningwarning#9a6700Warnings, conflict banners
successsuccess#1a7f37Success messages
donedone#8250df“Done” purple
linklink#0969daHyperlinks
scrollbarscrollbar#8c959fScrollbar handle
focusfocus#0969daFocus ring, hovered borders, active-row marker

GitHub Dark ​

TokenValue
backgroundbackground#0d1117
surfacesurface#161b22
surface_raisedsurface_raised#21262d
sunkensunken#161b22
texttext#e6edf3
text_mutedtext_muted#9fa7b2
accentaccent#1f6feb
accent_textaccent_text#ffffff
borderborder#30363d
selectionselection#264f78
hoverhover#21262d
dangerdanger#ff7b72
warningwarning#e3b341
successsuccess#3fb950
donedone#ab7df8
linklink#58a6ff
scrollbarscrollbar#6e7681
focusfocus#58a6ff

The other seven themes use the same roles with their own values. Theme::for_id(id) returns them; foundation/theme/palette.rs is the single source of truth.

How tokens reach egui ​

theme::apply_tokens(ctx, &theme):

egui fieldToken
visuals.panel_fillbackground
visuals.window_fillsurface
visuals.faint_bg_colorhover
visuals.extreme_bg_colorsunken
visuals.hyperlink_colorlink
visuals.selection.bg_fillselection
visuals.selection.stroketext
visuals.window_strokeborder
visuals.error_fg_colordanger
visuals.warn_fg_colorwarning
visuals.override_text_colortext
widget inactive fillsurface
widget hovered fillhover
widget active fillaccent

The function also installs spacing, scrollbar metrics, and the type scale. The installed WorkbenchStyle is re-applied after the visuals, so a theme change cannot reset density or radii.

Reading tokens in components ​

rust
use egui_workbench::theme;

let tokens = theme::current(ui.ctx());
let success = tokens.success;   // egui visuals does not carry this role
let muted = tokens.text_muted;

theme::current returns the tokens last applied with apply_id or apply_tokens. If none were applied, it falls back to GitHub Light or Dark based on the current visuals, so a test harness always has a sensible theme.

Contrast guarantee ​

Theme::accessibility_issues() checks the pairs that matter:

PairMinimum
text on background4.5:1
text on surface4.5:1
text_muted on background4.5:1
link on background4.5:1
accent_text on accent4.5:1
danger on background4.5:1
focus on background3:1

Every built-in theme returns an empty vector, and the unit tests enforce it. Use the same method after defining a custom theme.

Helpers ​

FunctionPurpose
theme::mix(a, b, t)Blend two colors in sRGB (0 = a, 1 = b)
theme::relative_luminance(color)WCAG relative luminance
theme::contrast_ratio(a, b)WCAG contrast ratio
theme::readable_on(fill, dark)White or the supplied dark color, whichever reads better
theme::current(ctx)Installed tokens
theme::motion_enabled(ctx)Whether animations are on

Theme::border_stroke() returns a 1 pt border in the border token. For borders and radii that follow the installed shape, use the style instead: style::get(ctx).border(theme.border) and style::get(ctx).control(). Theme::radius() is deprecated for that reason.

Released under MIT OR Apache-2.0. Icons: Lucide (ISC) and Material Icon Theme (MIT).