---
title: "Expressions"
description: "The expression forms and what they evaluate to."
---


An expression produces a value.
A literal is the simplest form: a number such as `42` or `3.14`, a number with a unit such as `100px` or `250ms`,
the boolean `true` or `false`, a [string](../../property-types/strings/#string) with `\{ }` interpolation,
or a [color](#color-literals).
The other forms are a [reference](#references), an [operator or conditional expression](../operators/),
a [member access or index](../operators/#member-access-and-indexing), a function or callback call,
an array or struct literal, and a macro such as `@image-url` or `@tr`.

Parentheses group a nested expression.

## Color Literals

A color literal consists of `#` followed by 3, 4, 6, or 8 hexadecimal digits:
`#rgb`, `#rgba`, `#rrggbb`, or `#rrggbbaa`.
The digits are case-insensitive.
Any other number of digits is an error.

The digits specify the red, green, blue, and alpha channels, in this order.
When the alpha channel is absent, the color is fully opaque.

In the 3- and 4-digit forms, each digit specifies a channel with the digit duplicated:
`#18f` is the same color as `#1188ff`.

A color literal evaluates to a value of type `color`.

## Length Literals

A length literal consists of a number directly followed by a unit, for example `120px`.

```slint
export component Example inherits Window {
    Rectangle {
        width: 120px;
        height: 80px;
        background: #2a6e3f;
    }
}
```



The number may be fractional, as in `10.5px`.
Length units include `px`, `phx`, `cm`, `mm`, `in`, `pt`, and `rem`.

A length literal evaluates to a value of type `length`.

## Integer Literals

An integer literal is a whole number written without a unit, for example `42`.

An integer literal evaluates to a value of type `int`.


## Image Literals

An image literal consists of `@image-url(`, a string literal in double
quotes, and `)`.

```slint
export component Example inherits Window {
    in property <image> logo: @image-url("images/logo.png");
}
```

The string is the path of an image file: an absolute path, or a path
resolved relative to the directory of the `.slint` file that contains the
literal.

An empty string evaluates to no image.

An image literal evaluates to a value of type `image`.

The path may also name a file on the compiler's include path, and an image
can also be loaded from a `data:` URI or a URL;
the [image type](../../property-types/images/) describes these forms and the
`nine-slice` argument.


## References

```slint
export component Example inherits Window {
    in property <color> tint;
    Rectangle {
        background: root.tint;
        width: self.height;
    }
}
```

A property reference refers to a property.
It is a property name, optionally preceded by an element reference and a `.`.

The element reference is `self` for the enclosing element, `parent` for its parent,
`root` for the component's root element, or an element `id`.

The predefined names `true` and `false` are references to the two values of type `bool`.

A name without an element reference follows the [lookup rules](../name-resolution/#lookup-rules).

The name shall refer to a property of the referenced element.

When reading, a property reference evaluates to the value of the referenced property,
and has that property's type.

Without an element reference, a name may also resolve to a local variable, a callback, or a function.

A reference may also name an [enumeration](../structs-and-enums/#enums) value or a [global](../globals/)'s property.