---
title: "Named Slots"
description: "Experimental named slots for multiple content insertion points."
---
A `slot` is a named insertion point where a component renders content supplied by its user.
It generalizes the built-in `@children` placeholder: instead of a single anonymous block of children, a component can declare several slots and place each one at a distinct location in its own layout.

> **Note**: named slots are experimental and subject to change.
> Enable them with the `named-slots` [experimental feature](../overview/).
> Tracking issue: [slint-ui/slint#6258](https://github.com/slint-ui/slint/issues/6258).

## Declaring a slot

Use the `slot` keyword inside a component to declare a slot, then render it at the desired location by writing the slot's name as an empty element.

```slint
export component Base inherits Rectangle {
    slot header;
    slot footer;

    VerticalLayout {
        header {}      // render site for the `header` slot
        @children      // the default slot
        footer {}      // render site for the `footer` slot
    }
}
```

A declared slot must be rendered exactly once.
`@children` continues to work as before and represents the default, unnamed slot.

## Assigning a slot

The user of a component fills a slot with the `<<` operator, naming the slot on the left and the content on the right.
Content that is not assigned to a named slot goes to `@children`, as usual.

```slint no-test
export component App inherits Rectangle {
    Base {
        header << Rectangle { background: blue; }
        Text { text: "Main Content"; }   // goes to @children
        footer << Rectangle { background: gray; }
    }
}
```

Assigning an untyped slot is optional.
An unassigned untyped slot renders its [default content](#default-content), or nothing if it has none.
[Typed slots](#typed-slots) require a supplied component.

## Default Content

Give an untyped slot default content with `<<` in its declaration.
The component shows the default until a caller assigns the slot.
An assignment replaces the whole default, including its layout constraints.

```slint
export component Panel inherits Rectangle {
    slot heading << Text { text: "Untitled"; }
    VerticalLayout {
        heading { }
        @children
    }
}

export component App inherits Window {
    VerticalLayout {
        Panel {
            Text { text: "Shows the default heading"; }
        }
        Panel {
            heading << Text { text: "Project"; }
            Text { text: "Details"; }
        }
    }
}
```

Assign `{ }` to remove the default content without replacing it:

```slint no-test
Panel {
    heading << { }
}
```

The default content is a single element.
Wrap an `if` or `for` in an element to use it as default content.
Default content can't contain slot placeholders or `@children`.
A `Tab` in a `TabWidget` and a `Menu` in a `ContextMenuArea` or `SystemTrayIcon` can't be default content;
declare them as children instead.

Replacing the default removes its elements, so references to them from outside the default content are errors:

```slint no-test
component Foo inherits Rectangle {
    slot bar << label := Text { text: "Default"; }
    Text { text: label.text; }   // error
    bar { }
}
```

References between elements inside the same default content are allowed.
For shared state, declare a property on the component and bind both the default content and other elements to it.

A slot that's forwarded to another component's slot can't have default content.
Set the default on the target slot instead.
Typed slots don't support default content yet.

### Filling Inherited Slots

A derived component fills an inherited untyped slot with `<<` at its root.
The assignment becomes the slot's default content: the slot stays open, and callers of the derived component can replace it.
Assigning `{ }` removes the inherited default and also leaves the slot open.

```slint
component Base inherits Rectangle {
    slot content << Text { text: "Base default"; }
    VerticalLayout {
        content { }
    }
}

component Derived inherits Base {
    content << Text { text: "Derived default"; }
}

export component App inherits Window {
    VerticalLayout {
        Derived { }   // shows "Derived default"
        Derived {
            content << Text { text: "Caller"; }
        }
    }
}
```

Don't redeclare an inherited slot or place it again in the derived component.
The slot keeps the position its base component gives it.

## Referencing a slot

The name bound to a slot is a regular element reference, so its properties can be read like any other element.

```slint no-test
export component App inherits Rectangle {
    Base {
        header << Rectangle { height: 8px; }
        out property <length> header-y: header.absolute-position.y;
    }
}
```

## Forwarding a slot

A component can forward one of its own slots to a slot of a child component, again with the `<<` operator.
This lets a wrapper expose a nested component's slots as its own.

```slint
export component SlotHost inherits Rectangle {
    slot host-header;
    VerticalLayout {
        host-header {}
        @children
    }
}

export component Outer inherits Rectangle {
    slot header;
    SlotHost {
        host-header << header;   // forward Outer's `header` into SlotHost's `host-header`
        @children
    }
}
```

## Full example

```slint
export component Card inherits Rectangle {
    slot header;
    slot footer;

    VerticalLayout {
        header {}
        @children
        footer {}
    }
}

export component App inherits Window {
    Card {
        header << Text { text: "Title"; }
        Text { text: "Body content"; }
        footer << Text { text: "Footer"; }
    }
}
```

## Typed Slots

Declare `slot <InterfaceName> name;` when a component needs to interact with supplied content through an [interface](./interface).

The host can bind interface inputs, read outputs, modify `in-out` properties, call public functions, and connect callbacks.
Members outside the interface aren't available through the host's slot reference.

```slint
interface Action {
    in property <bool> enabled;
    callback activated();
}

component ActionHost inherits Rectangle {
    in property <bool> enabled: true;
    callback activated();

    slot <Action> action;
    action {
        enabled: root.enabled;
        activated => { root.activated(); }
    }
}

component PointerAction {
    in property <bool> enabled;
    callback activated();

    Text { text: "Click me"; }
    TouchArea {
        enabled: root.enabled;
        clicked => { root.activated(); }
    }
}

export component App inherits Window {
    width: 200px;
    height: 80px;

    ActionHost {
        action << PointerAction { }
        activated => { debug("Activated"); }
    }
}
```

The supplied component must provide the interface's members with matching types, visibility, and function signatures.
Pure interface functions require pure implementations.
An explicit `implement` declaration isn't required.
Members can be declared directly, inherited, or delegated with `implement Action <=> child`.

A typed slot requires exactly one component when its host is instantiated.
A derived component can leave the slot open for its caller.
Unlike an untyped slot, a typed slot that a derived component fills is closed to that component's callers.
When forwarding between two typed slots, both must declare the same interface.

Typed placeholders accept property bindings, callback connections, and property change handlers, but not child elements or new declarations.
Defining handlers for the same callback in both the placeholder and supplied component is an error.
Property bindings follow the existing priorities; more local bindings take precedence.

## Current limitations

The named slot feature is in its early stages. The following restrictions apply:

- The name `children` is reserved for the default slot. Use `@children` to render it.

- A declared slot must be rendered exactly once, and it may not be placed inside a `for`, `if`, or `match` element.

- A slot cannot be placed inside a `PopupWindow` or a `ComponentContainer`.

- Slot assignment and forwarding are only valid on components, and each slot may be assigned at most once.