VStack


目录

This feature is still experimental. “Experimental” means this is an early implementation subject to drastic and breaking changes.

VStack (or Vertical Stack) is a layout component that arranges child elements in a vertical line.

Usage

VStack can render anything inside.

import { __experimentalVStack as VStack } from '@wordpress/components';

function Example() {
    return (
        <VStack>
            <span>Code</span>
            <span>is</span>
            <span>Poetry</span>
        </VStack>
    );
}

Props

alignment: HStackAlignment | CSSProperties['alignItems']

Determines how the child elements are aligned.

direction: FlexDirection

The direction flow of the children content can be adjusted with direction. column will align children vertically and row will align children horizontally.

expanded: boolean

Expands to the maximum available width (if horizontal) or height (if vertical).

justify: CSSProperties['justifyContent']

Horizontally aligns content if the direction is row, or vertically aligns content if the direction is column.
In the example below, flex-start will align the children content to the left.

spacing: CSSProperties['width']

The amount of space between each child element. Spacing in between each child can be adjusted by using spacing.
The value of spacing works as a multiplier to the library’s grid system (base of 4px).

wrap: boolean

Determines if children should wrap.

Spacer

When a Spacer is used within an VStack, the Spacer adaptively expands to take up the remaining space.

import {
    __experimentalSpacer as Spacer,
    __experimentalVStack as VStack,
} from '@wordpress/components';

function Example() {
    return (
        <VStack>
            <span>Code</span>
            <Spacer>
                <span>is</span>
            </Spacer>
            <span>Poetry</span>
        </VStack>
    );
}

Spacer can also be used in-between items to push them apart.

import {
    __experimentalSpacer as Spacer,
    __experimentalVStack as VStack,
} from '@wordpress/components';

function Example() {
    return (
        <VStack>
            <span>Code</span>
            <Spacer />
            <span>is</span>
            <span>Poetry</span>
        </VStack>
    );
}

版本号 #2
由 壳壳虫 创建于 2026-10-31 18:15:41 UTC
由 壳壳虫 更新于 2026-10-31 18:15:43 UTC