Skip to content

Spacing

Control spacing with margin, padding, and gap utilities.

Apply margin to all sides or specific directions:

<View className="m-4" /> // margin: 16
<View className="m-0" /> // margin: 0
<View className="m-8" /> // margin: 32
<View className="mx-4" /> // marginHorizontal: 16
<View className="my-2" /> // marginVertical: 8
<View className="mt-4" /> // marginTop: 16
<View className="mr-2" /> // marginRight: 8
<View className="mb-6" /> // marginBottom: 24
<View className="ml-3" /> // marginLeft: 12

Apply padding to all sides or specific directions:

<View className="p-4" /> // padding: 16
<View className="p-0" /> // padding: 0
<View className="p-8" /> // padding: 32
<View className="px-4" /> // paddingHorizontal: 16
<View className="py-2" /> // paddingVertical: 8
<View className="pt-4" /> // paddingTop: 16
<View className="pr-2" /> // paddingRight: 8
<View className="pb-6" /> // paddingBottom: 24
<View className="pl-3" /> // paddingLeft: 12

Control spacing between flex items:

<View className="flex-row gap-4">
<View className="flex-1 bg-blue-500" />
<View className="flex-1 bg-red-500" />
</View>

Spacing values follow a scale where 1 = 4px:

ClassValue (px)
00
0.52
14
1.56
28
2.510
312
3.514
416
520
624
728
832
936
1040
1144
1248
1456
1664
2080
2496
28112
32128
36144
40160
44176
48192
52208
56224
60240
64256
72288
80320
96384

Use arbitrary values for custom spacing not in the preset scale:

<View className="m-[16px]" /> // margin: 16
<View className="p-[20px]" /> // padding: 20
<View className="mx-[24px]" /> // marginHorizontal: 24
<View className="gap-[12px]" /> // gap: 12
<View className="p-4 m-2 gap-3 bg-white rounded-lg">
<Text className="text-xl font-bold">Title</Text>
<Text className="text-base">Description</Text>
<View className="mt-2">
<Text className="text-sm text-gray-600">Footer</Text>
</View>
</View>
<View className="flex-row gap-4 p-4">
<View className="w-12 h-12 bg-blue-500 rounded" />
<View className="w-12 h-12 bg-red-500 rounded" />
<View className="w-12 h-12 bg-green-500 rounded" />
</View>
<View className="p-4 ios:p-6 android:p-8">
<Text>Platform-specific padding</Text>
</View>