> For the complete documentation index, see [llms.txt](https://react-native.books.c-k.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://react-native.books.c-k.dev/styling/flexbox.md).

# Flexbox

Flexbox is a system of positioning elements within the container. Developer can use flexbox to tell a react native how to position the elements within the the overall view tag. In default, react native will put the elements to the top left of its parent.&#x20;

For example, if you want to centre the content, you may need 2 properties.

* justifyContent
  * Used to move the element in vertical direction
  * Properties Setting
    * flex-end: push elements down to the very bottom
    * center: center middle
    * flex-start: default, top
* alignItems
  * Used to move the element in horizontal direction
  * Properties Setting
    * flex-start: default, start of line
    * center: center of line
    * flex-end: end of line

Flexbox is also used to layout multiple items within the container.

For example, given we target to build the layout like this,&#x20;

![](https://3241674717-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L_DfhjIgb2njPA7L1mD%2F-L_QS-yn_dKxzLLjdPz2%2F-L_QTJYCrrlbgYGQYmyd%2Fimage.png?alt=media\&token=a5bb0f16-adb4-4b66-841c-a86093776053)

But by default, react-native will look like this,

![](https://3241674717-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L_DfhjIgb2njPA7L1mD%2F-L_QS-yn_dKxzLLjdPz2%2F-L_QTOrKodYSoSEwo_4a%2Fimage.png?alt=media\&token=e4198e48-41bd-442f-b914-7ce39f799e46)

### flexDirection

Used to determine the item flow direction

![](https://3241674717-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L_DfhjIgb2njPA7L1mD%2F-L_QmuFQ4_iecL_td3Bm%2F-L_QniAva-IoVVRTR3N2%2Fimage.png?alt=media\&token=92086bab-2b31-4fac-be7c-433caa127f52)

```jsx
flex=1
// This properties indicates the layout occupation percentage. 
// The occupation of layout is depends on {value}/{num of item in the same level}

// Given
<View style={{flex:1}}></View> // occupy 1/4
<View style={{flex:2}}></View> // occupy 2/4
<View style={{flex:1}}></View> // occupy 1/4

// This property means that “please expand this component to fill the entire area content of the device”
```
