Skip to content

Styles and themes

Instead of repeating #791bff in every control, define the colors (and sizes) once in a global and use them everywhere. When you import from Figma, your file’s color variables arrive like this, in a global Tema.

ui/app-window.slint
import { Button, VerticalBox } from "std-widgets.slint";
export global Theme {
out property <color> primary: #791bff;
out property <color> background: #f4f5f8;
out property <color> text: #1a1b22;
out property <length> radius: 12px;
}
export component AppWindow inherits Window {
title: @tr("My app");
width: 360px;
height: 240px;
background: Theme.background;
default-font-size: 15px;
VerticalBox {
Text {
text: @tr("Welcome");
font-size: 24px;
font-weight: 700;
color: Theme.text;
}
Rectangle {
height: 80px;
background: Theme.primary;
border-radius: Theme.radius;
Text {
text: @tr("A card with the theme's colors");
color: white;
}
}
Button {
text: @tr("Continue");
primary: true;
}
}
}
src/main.rs
slint::include_modules!();
fn main() -> Result<(), slint::PlatformError> {
let ui = AppWindow::new()?;
// A global can also be read from Rust (and changed, if its properties are "in-out" or "in"):
// that's how you'd build a dark mode, for example.
let primary = ui.global::<Theme>().get_primary();
println!("Primary color: {primary:?}");
ui.run()
}
Keyword Who can change the property
in Rust (or whoever uses the component)
out Only the component itself; Rust reads it
in-out Both
(none) Only the component itself (private)

The controls from std-widgets.slint (buttons, check boxes, lists…) are drawn with a style. By default it’s fluent (Windows 11’s); there’s also material (Android), cupertino (macOS) and cosmic, each in light and dark (fluent-dark, material-light…). It’s chosen in build.rs:

build.rs
fn main() {
let config = slint_build::CompilerConfiguration::new().with_style("material".into());
slint_build::compile_with_config("ui/app-window.slint", config).expect("Couldn't compile the .slint interface");
}
  • The window’s default-font-family, default-font-size and default-font-weight apply to every text.
  • Each text can change them with font-family, font-size, font-weight (100 to 900) and font-italic.
  • To use your own font, import it at the top of the file: import "fonts/Inter.ttf"; and then font-family: "Inter";.

Wrap visible texts in @tr("…"). Without doing anything else they’re shown as they are; when you want to translate the app, Slint extracts those texts into .po files (the standard translation format) and picks the system’s language. Standard buttons (StandardButton: OK, Cancel…) already use @tr.

Next: Controls reference.