Match Elements
A match element conditionally renders elements from a set of cases based on the value of an expression.
It is a more readable alternative to a chain of if elements when you need to select between several mutually exclusive states.
Note:
matchis experimental and subject to change. Tracking issue: slint-ui/slint#1307 ↗.
Syntax
Section titled “Syntax”match <match-value> { <case-value>: ElementType { /* ... */ } <case-value>: ElementType { /* ... */ } *: ElementType { /* ... */ } // optional wildcard}Each <case-value> is a literal that is compared against the <match_value>. If a wildcard case * is present, it renders when none of the explicit cases match.
Examples
Section titled “Examples”Matching on an integer
Section titled “Matching on an integer”export component StatusIndicator { in property <int> status: 0;
match status { 0: Rectangle { background: green; } 1: Rectangle { background: yellow; } 2: Rectangle { background: red; } *: Rectangle { background: gray; } }}Matching on a boolean
Section titled “Matching on a boolean”export component Toggle { in-out property <bool> checked: false;
match checked { true: Rectangle { background: blue; } false: Rectangle { background: lightgray; } }}Matching on an enum
Section titled “Matching on an enum”enum Mode { View, Edit, Preview }
export component Editor { in-out property <Mode> mode: Mode.View;
match mode { Mode.View: Text { text: "Viewing"; } Mode.Edit: TextInput { } Mode.Preview: Rectangle { background: black; } }}Matching on a string
Section titled “Matching on a string”export component Greeting { in property <string> lang: "en";
match lang { "en": Text { text: "Hello"; } "sp": Text { text: "Hola"; } "fr": Text { text: "Bonjour"; } *: Text { text: "Hi"; } }}Wildcard case
Section titled “Wildcard case”The * case acts as a catch-all that renders when no explicit case matches the expression.
It must appear as the last case, and there must be at least one explicit case before it.
match answer { 42: Text { text: "Correct!"; } *: Text { text: "Incorrect"; }}Empty element
Section titled “Empty element”Any case that evaluates to the empty element { } will be skipped and not rendered. Any case can evaluate to the empty element, including the wildcard case.
match show { true: Text { text: "Hi"; } false: { }}match toggle { 0: Rectangle { background: white; } 1: Rectangle { background: black; } *: { }}Current limitations
Section titled “Current limitations”The match element feature is in its early stages. The following restrictions apply:
-
Cases must be literal values. Computed expressions, property references, destructured values, and function calls are not allowed as case values. Only plain literals (integers, floats, booleans, strings, enum variants, colors, lengths) are accepted.
// Property reference as a case valuematch value {some-property: Rectangle { } // error}// String concatenation as a case valuematch greeting {"hello " + "world": Text { } // error}// Function call as a case valuematch count {func(5): Rectangle { } // error}slint -
Float comparisons produce a warning. Comparing floating-point values for exact equality is not reliable. The compiler emits a warning for each float case value.
-
@childrencannot appear inside a match case. Placing the@childrenplaceholder inside any case element is an error. -
matchcannot appear in global components or interfaces. Only regular components support match elements. -
No exhaustiveness checking. Match elements do not verify that all possible values are covered. A missing case simply renders nothing.
-
No duplicate case detection. No warning will be produced if the same value appears in two different cases, and both components will render.
© 2026 SixtyFPS GmbH