Compose controls space with three tools: Modifier.padding adds space around or inside a composable, Arrangement decides how a Row or Column distributes its children along the main axis, and Alignment positions children on the cross axis. Together they cover almost every compose padding arrangement alignment question a beginner has. Modifier order matters, because each modifier wraps the result of the one before it.
This guide uses the Compose Material 3 library and Kotlin. Every example is a complete composable you can paste into a setContent block or a preview.
padding reserves empty space. It accepts a single value for all sides, horizontal and vertical values, or four individual sides.
The gray background is drawn first, then 16 dp of padding is added inside it, so the text sits in the middle of a larger gray box. Other forms you will use:
Modifier.padding(horizontal = 24.dp, vertical = 8.dp) for symmetric spacing.Modifier.padding(start = 16.dp, top = 8.dp) for single sides. Use start and end instead of left and right so right-to-left languages work.Modifier.padding(PaddingValues(16.dp)) when you want to pass a value object around.Modifiers apply from the outside in. Swap the order in the example and the result changes.
Compose has no separate margin. Padding placed before background or clickable acts like a margin, and padding placed after acts like padding inside the box.
Column and Row take an Arrangement for the main axis. For a Column the main axis is vertical, for a Row it is horizontal.
| Arrangement | Effect |
|---|---|
Arrangement.Top / Start | Children packed at the start (the default for Column and Row) |
Arrangement.Center | Children packed in the middle |
Arrangement.Bottom / End | Children packed at the end |
Arrangement.SpaceBetween | First and last child touch the edges, equal gaps between |
Arrangement.SpaceAround | Equal space around each child, half-size at the edges |
Arrangement.SpaceEvenly | Equal gaps everywhere, including the edges |
Arrangement.spacedBy(12.dp) | A fixed gap between children |
Arrangement only has a visible effect when the container is larger than its content, so give it a size such as Modifier.fillMaxWidth().
Cancel sits at the left edge and Save at the right edge, inside 16 dp of outer padding.
Arrangement.spacedBy is the cleanest way to space a list of items, because you do not pad each child.
The cross axis is horizontal in a Column and vertical in a Row. Use horizontalAlignment on a Column and verticalAlignment on a Row.
The types differ: Column expects Alignment.Horizontal values such as Start, CenterHorizontally and End, while Row expects Alignment.Vertical values such as Top, CenterVertically and Bottom. Mixing them is a compile error.
Container-wide alignment applies to all children. To place one child differently, use Modifier.align inside the scope of a Column, Row or Box.
Box stacks children and accepts two-dimensional alignments like Alignment.TopStart and Alignment.Center. Modifier.align is only available inside these scopes, which is why you cannot call it on an arbitrary composable.
The outer padding gives the screen a margin, spacedBy sets the vertical rhythm, and the alignments center everything. Use Spacer(Modifier.height(16.dp)) only when one gap must differ from the rest.
No. Use Modifier.padding before background, border or clickable to get margin-like space outside, and after them for space inside.
The container is probably only as big as its content. Add fillMaxWidth(), fillMaxHeight() or fillMaxSize() so there is free space to distribute.
Arrangement distributes children along the main axis, and Alignment positions them on the cross axis. In a Column that means vertical arrangement and horizontal alignment.
Use dp for layout spacing and sp for text size. Text size in sp follows the user font setting, while spacing stays fixed.
Modifier.padding adds space, and its position in the modifier chain decides whether it behaves like margin or inner padding.Arrangement spreads children along the main axis and needs spare room to show its effect.Alignment positions children on the cross axis, and Modifier.align overrides it for one child.Arrangement.spacedBy is the simplest way to keep consistent gaps in a list of items.