Skip to main content

Learning Objectives

By the end of this module, you’ll understand:
  • Flexbox fundamentals and layout principles
  • Flex direction and wrapping
  • Justify content and align items
  • Flex sizing (grow, shrink, basis)
  • Absolute positioning
  • Common layout patterns

Flexbox Fundamentals

Flexbox is the primary layout system in React Native. Unlike CSS on the web, all components in React Native use Flexbox by default — there is no display: block or display: inline. Everything is a flex container. Think of Flexbox like packing items into a suitcase. You decide the direction items are placed (left-to-right or top-to-bottom), how leftover space is distributed, and what happens when items do not fit. Key difference from web CSS: In React Native, the default flexDirection is column (vertical), not row (horizontal). This matches mobile conventions where screens are taller than they are wide and content naturally flows top-to-bottom.

Flex Direction

Controls the main axis — the direction children are laid out. Once you set the main axis, the cross axis is always perpendicular to it. Every alignment property in Flexbox refers to one of these two axes, so understanding this distinction is critical.

Justify Content

Aligns children along the main axis:

Justify Content Options:

  • flex-start (default) - Align to start
  • flex-end - Align to end
  • center - Center items
  • space-between - Even spacing, edges at container bounds
  • space-around - Even spacing including before first and after last
  • space-evenly - Equal spacing between all items including edges

Align Items

Aligns children along the cross axis:

Align Items Options:

  • stretch (default) - Stretch to fill
  • flex-start - Align to cross-start
  • flex-end - Align to cross-end
  • center - Center on cross axis
  • baseline - Align text baselines

Align Self

Override alignItems for individual children:

Flex Sizing

Flex sizing controls how available space is distributed among children. Think of it like splitting a restaurant bill: flex values are each person’s share. A child with flex: 2 gets twice the space of a sibling with flex: 1.

flex

Defines how a component grows relative to siblings:

flexGrow

Similar to flex, but the key difference is that flexGrow distributes extra space after each child’s base size is accounted for, while flex ignores base size entirely. In practice, use flex for simple proportional layouts and flexGrow when children have a meaningful minimum width/height:

flexShrink

Controls how components shrink when space is limited:

flexBasis

Sets the initial size before flexGrow/flexShrink:

Flex Wrap

Controls wrapping of flex items:

Flex Wrap Options:

  • nowrap (default) - Single line
  • wrap - Multi-line, top to bottom
  • wrap-reverse - Multi-line, bottom to top

Align Content

Aligns wrapped lines within container (only works with flexWrap):
Options: flex-start, flex-end, center, stretch, space-between, space-around

Positioning

React Native supports two positioning modes. Relative positioning is the default and rarely needs to be set explicitly. Absolute positioning removes an element from the normal layout flow — it no longer pushes other elements around, similar to pulling a sticky note off a stack and placing it anywhere on your desk.

Relative Positioning (Default)

Elements positioned according to normal flow, with optional offsets from their natural position:

Absolute Positioning

Removes element from document flow:

Absolute Fill Shortcut


Z-Index

Controls stacking order of positioned elements:

Common Layout Patterns

Center Content

Row with Space Between

Grid Layout

Card with Overlay


Gap Property

Before gap, you had to use margins on individual children to space them apart, which always created an unwanted margin on the first or last item. gap solves this cleanly — it adds space between items only, never at the edges. If you have used CSS Grid’s gap, this is the same concept.
Note: Gap property requires React Native 0.71+ or Expo SDK 48+

Layout Props Reference

Container Props

Item Props

Position Props


Best Practices

  1. Use flex: 1 for components that should fill available space — this is the single most important Flexbox pattern in React Native. Forgetting it is the most common reason a screen appears blank.
  2. Avoid fixed dimensions when possible — use flex and percentages. Fixed pixel values that look perfect on your test device will break on a different screen size.
  3. Center anything with justifyContent: 'center' and alignItems: 'center' — this two-property combo works regardless of flexDirection and is the universal centering recipe.
  4. Understand the axesjustifyContent controls the main axis (direction of flexDirection), alignItems controls the cross axis (perpendicular). This is the mental model that makes all of Flexbox click.
  5. Use gap instead of margins for spacing between items — it is cleaner, avoids edge-margin bugs, and requires React Native 0.71+.
  6. Test on extreme screen sizes — Flexbox is responsive by default, but edge cases like the iPhone SE (320pt wide) and iPad (768pt+ wide) often reveal layout assumptions. Run your app on both during development.