# Label

> Text with a theme color, size and weight; `muted` for secondary text. A Pyzed component for Python desktop GUIs, with examples and its API.

Source: https://albakore.github.io/pyzed/library/label/

:::tip[In plain words]
Plain text on the screen, in the colors of the current theme.
:::

Text that takes its color from the theme. `color` is a theme token (`"text"`, `"accent"`, `"error"`…) or a hex color, and `size` is a named step (`"xs"` to `"2xl"`) or a number. `ui.muted(...)` is a label with the `"text_muted"` color, for secondary text.

`ui.label` · Category: [Display](https://albakore.github.io/pyzed/library/#display) · [Full reference →](https://albakore.github.io/pyzed/reference/ui/#label)

**Code:**

```python
pz.column([
    ui.label("Pyzed draws native UIs with Iced."),
    ui.muted("Secondary text uses the muted color."),
    ui.label("Accent and semibold", color="accent", weight="semibold"),
    ui.label("def mono(): ...", mono=True, size="sm"),
], spacing=8)
```

## When to use

- For any text in a themed UI: it follows theme changes, unlike a hard-coded `pz.text`.
- Use `ui.muted` for descriptions, hints and metadata.
- For titles use [Heading](https://albakore.github.io/pyzed/library/heading/).

## Usage

```python
import pyzed as pz
from pyzed import ui

pz.column([
    ui.label("Pyzed draws native UIs with Iced."),
    ui.muted("Secondary text uses the muted color."),
    ui.label("Accent and semibold", color="accent", weight="semibold"),
    ui.label("def mono(): ...", mono=True, size="sm"),
], spacing=8)
```

## Variants

:::note[About these captures]
Each capture is recorded by pyzed itself, off-screen at 2x, in One Dark or One Light to match this site's theme, and cropped to the component so it shows at its real size. The pointer hovers, presses or types into it; a component that does not react to the pointer cycles through a few themes. With reduced motion you see the first frame. Open **Code** under a capture to see the snippet that draws it; free names such as `on_save` stand for your own callbacks.
:::

### Size

Named sizes follow the theme's font size; a number is a size in pixels.

```python
ui.label("Extra small", size="xs")
```

```python
ui.label("Small", size="sm")
```

```python
ui.label("Medium", size="md")
```

```python
ui.label("Large", size="lg")
```

```python
ui.label("Extra large", size="xl")
```

```python
ui.label("Huge", size="2xl")
```

### Color

```python
ui.label("Text")
```

```python
ui.muted("Muted text")
```

```python
ui.label("Accent", color="accent")
```

```python
ui.label("Success", color="success")
```

```python
ui.label("Warning", color="warning")
```

```python
ui.label("Error", color="error")
```

```python
ui.label("Any hex color", color="#c678dd")
```

### Weight and style

```python
ui.label("Normal", weight="normal", size="lg")
```

```python
ui.label("Medium", weight="medium", size="lg")
```

```python
ui.label("Semibold", weight="semibold", size="lg")
```

```python
ui.label("Bold", weight="bold", size="lg")
```

```python
ui.label("Italic", italic=True, size="lg")
```

```python
ui.label("def mono(): ...", mono=True)
```

## Events

Label has no events of its own: it shows what you give it. Like every widget it also has the **18 common events** (`click`, `double_click`, `right_click`, `mouse_enter`, `drag`, `key_down`, `resize`…), attached with `.on(...)`: see [Events](https://albakore.github.io/pyzed/guides/events/) and [Events of every component](https://albakore.github.io/pyzed/library/events/).

## Properties and API

### `ui.label`

```python
label(
    content,
    *,
    color='text',
    size='md',
    weight=None,
    mono=False,
    italic=False,
    wrap=True,
    theme=None,
    **kwargs,
)
```

Text with a theme color.

| Property | Default | Description |
| --- | --- | --- |
| `content` | *required* | Content: a `Widget`, a string or a number (converted to text). |
| `color` | `"text"` | Theme token or hex color. Defaults to `"text"`. |
| `size` | `"md"` | `"xs"` (11), `"sm"` (12), `"md"` (13.5), `"lg"` (16), `"xl"` (20), `"2xl"` (26) or a number. |
| `weight` | `None` | Weight: `"medium"`, `"semibold"`, `"bold"`… |
| `mono` | `False` | Uses the monospace font (IBM Plex Mono). |
| `italic` | `False` | Italic. |
| `wrap` | `True` | Line wrapping. |
| `theme` | `None` | Theme to use instead of the current one (`pyzed.theme.current()`). |
| `**kwargs` | — | Passed to `pyzed.text`. |

[Full reference →](https://albakore.github.io/pyzed/reference/ui/#label)

### `ui.muted`

```python
muted(content, **kwargs)
```

A `label` with the `"text_muted"` color.

| Property | Default | Description |
| --- | --- | --- |
| `content` | *required* | Content: a `Widget`, a string or a number (converted to text). |
| `**kwargs` | — | Same as `label`. |

[Full reference →](https://albakore.github.io/pyzed/reference/ui/#muted)

## Related

- [Heading](https://albakore.github.io/pyzed/library/heading/): Semibold titles in three levels.
- [Kbd](https://albakore.github.io/pyzed/library/kbd/): Keyboard shortcuts drawn as keys, with symbols on macOS.
- [Badge](https://albakore.github.io/pyzed/library/badge/): A small pill for statuses, versions and counters.
