Flexbox

Also called Flex layout

Also known as
Flex layout
Mentioned in
View ComponentYoga
Updated

What is Flexbox in React Native?

Flexbox is the layout system React Native uses for every view. It matches CSS Flexbox closely, with a column default direction and a few React Native specific differences.

Flexbox is how you lay out every screen in React Native. There is no grid, no float, and no absolute positioning by default — layout is flex containers all the way down, computed by the Yoga engine.

The three properties that do most of the work:

  • flexDirection — the main axis, column (default) or row
  • justifyContent — distribution along the main axis
  • alignItems — alignment across the main axis

Differences from web CSS that catch newcomers:

Web CSSReact Native
Default flexDirectionrowcolumn
Default alignContentstretchflex-start
flex valueshorthand stringa single number
Unitspx, rem, %unitless density-independent numbers

flex: 1 means "take all remaining space", which is why a root screen container almost always has it. If a view is invisible, the usual cause is a parent with no height rather than a styling mistake on the view itself.

See layout with Flexbox.