Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Wrap

The wrap property controls whether children overflow and wrap onto a new line when they exceed the available space in a row or column layout.

Values

ValueDescription
no-wrapChildren are clipped at the container boundary. This is the default.
wrapChildren that overflow wrap onto a new row or column.

Using wrap in Rust

HStack::new(cx, |cx| {
    for i in 0..10 {
        Label::new(cx, format!("Item {}", i))
            .width(Pixels(80.0))
            .height(Pixels(30.0));
    }
})
.wrap(LayoutWrap::Wrap)
.width(Pixels(300.0));

Using wrap in CSS

.tag-list {
    layout-type: row;
    wrap: wrap;
    gap: 4px;
}

Gap between wrapped lines

Combined with the gap property, wrap creates a tiled layout of fixed-size items:

HStack::new(cx, |cx| {
    // items...
})
.wrap(LayoutWrap::Wrap)
.gap(Pixels(8.0));

See also