Skip to main content
These modifiers control where a component sits and how much space it claims. frame sets fixed or flexible dimensions; containerRelativeFrame sizes a component relative to its nearest scrollable container; padding adds space around it. offset shifts the visual position without affecting layout, zIndex controls stacking order inside a ZStack, and layoutPriority decides which sibling wins when space is tight.

frame

Sets the size of a component using fixed dimensions or flexible constraints.
object
required
Fixed frame.
object
required
Flexible frame.
The fixed frame overload sets exact dimensions. The flexible frame overload sets constraints — the component sizes itself within those bounds based on its content and the parent’s size proposal. Use Infinity for maxWidth or maxHeight to make the component expand to fill all available space. Fixed size
Fixed width only
Full-width with leading alignment
Minimum and maximum constraints
Full-screen background
Fixed size with alignment

containerRelativeFrame

Sizes a component relative to its nearest container.
Axis
required
Fill container overload: the axis along which the component fills the container. See Axis.
object
required
Grid subdivision overload.
object
required
Fractional sizing overload.
The nearest container is the closest ancestor ScrollView, List, or NavigationStack. The modifier sizes the component relative to that container’s visible area, not the full scrollable content. The grid subdivision form calculates the cell width as: (containerWidth - (count - 1) * spacing) / count * span + (span - 1) * spacing. Fill the container horizontally
Grid layout — 3 columns with spacing
Span multiple columns
Fractional sizing — 80% of container width
Horizontal scroll with fixed-width cards

padding

Adds padding around a component.
number
The padding amount in points. When called with a single number, applies equal padding on all edges.
EdgeSet
Which edges to apply padding to. See EdgeSet. When omitted, padding is applied to all edges.
Uniform padding
Edge-specific padding
Vertical padding
Single edge
Combined with background Padding is applied before the background, so the background extends to cover the padded area.

offset

Offsets the component’s visual position without affecting layout.
object
required
The offset values in points.
The offset is purely visual. The component’s original layout space is preserved — surrounding components aren’t affected by the offset. For layout-affecting position changes, use padding instead. Shifting a component
Overlapping badge
Vertical offset only

zIndex

Controls stacking order in a ZStack.
number
required
The stacking priority. Higher values render on top of lower values. The default is 0.
zIndex only affects rendering order within the same parent container. Without it, components in a ZStack render in order: first child at the bottom, last child on top. Negative values are valid and place the component behind siblings with the default zIndex(0). Bring a component to front
Layered cards
Dynamic z-ordering

layoutPriority

Sets the layout priority for space distribution among siblings.
number
required
The layout priority. Higher values receive preference for available space. Default is 0.
Layout priority only matters when sibling components compete for limited space within a parent container (e.g., HStack, VStack). All components default to a priority of 0. A component with priority 1 is offered its ideal size before components with priority 0. Negative values are valid and cause the component to shrink before siblings. Prioritizing one text over another When two texts compete for space in an HStack, the one with higher layout priority gets its full width before the other.
Preventing truncation

See also

  • aspectRatio — sets the width-to-height ratio of content
  • fixedSize — uses ideal size instead of the parent’s proposal
  • Alignment — alignment values for frame and corner-aligned overlays
  • Axis — axis values for containerRelativeFrame
  • EdgeSet — edge values for padding