Spacing is an important part of designing React Native applications.
Proper spacing makes mobile interfaces easier to read, understand
and use. React Native mainly uses properties such as
padding, margin, gap,
rowGap and columnGap to control spacing
between components.
padding: 20 means a spacing value of 20, rather than
writing 20px as you commonly would in web CSS.
Spacing means the empty area between or around UI elements. It helps separate different parts of an application.
const styles = StyleSheet.create({
box: {
padding: 20,
margin: 10
}
});
Good spacing creates a cleaner and more comfortable user interface.
Padding creates space inside a component, while margin creates space outside a component.
const styles = StyleSheet.create({
box: {
padding: 20,
margin: 10
}
});
Understanding this difference is essential when designing layouts.
The padding property adds equal space inside all
four sides of a component.
const styles = StyleSheet.create({
card: {
padding: 20
}
});
All four sides receive the same padding value.
The paddingTop property controls the space inside
the top edge of a component.
const styles = StyleSheet.create({
box: {
paddingTop: 30
}
});
It is useful when content needs additional space above it.
The paddingBottom property controls the space below
the content inside a component.
const styles = StyleSheet.create({
box: {
paddingBottom: 20
}
});
These properties control the internal space on the left and right sides.
const styles = StyleSheet.create({
box: {
paddingLeft: 15,
paddingRight: 15
}
});
They are useful for controlling horizontal spacing.
You can use paddingVertical and
paddingHorizontal for easier two-direction spacing.
const styles = StyleSheet.create({
button: {
paddingVertical: 12,
paddingHorizontal: 20
}
});
This is commonly useful for buttons, cards and form elements.
The margin property creates space outside a component.
const styles = StyleSheet.create({
box: {
margin: 20
}
});
The same margin value is applied around all four sides.
The marginTop property adds space above a component.
const styles = StyleSheet.create({
title: {
marginTop: 20
}
});
It is commonly used to separate one section from another.
The marginBottom property adds space below a component.
const styles = StyleSheet.create({
title: {
marginBottom: 15
}
});
It is frequently used to create space between headings and other components.
const styles = StyleSheet.create({
box: {
marginLeft: 10,
marginRight: 10
}
});
These properties control the external horizontal spacing of a component.
React Native provides marginVertical and
marginHorizontal for convenient spacing.
const styles = StyleSheet.create({
card: {
marginVertical: 10,
marginHorizontal: 15
}
});
Cards commonly use padding to keep their content away from the edges.
const styles = StyleSheet.create({
card: {
backgroundColor: 'white',
padding: 20,
borderRadius: 12
}
});
Without enough padding, card content can look crowded.
const styles = StyleSheet.create({
card: {
padding: 20,
marginBottom: 15,
borderRadius: 10
}
});
Using bottom margin is a simple way to create vertical space between multiple cards.
const styles = StyleSheet.create({
input: {
borderWidth: 1,
borderColor: '#CBD5E1',
borderRadius: 8,
padding: 12,
marginBottom: 15
}
});
A bottom margin separates one input field from the next field.
const styles = StyleSheet.create({
button: {
paddingVertical: 14,
paddingHorizontal: 20,
marginTop: 10,
marginBottom: 10
}
});
Padding controls the internal button size while margin separates the button from nearby components.
The gap property can be used to create consistent
spacing between children in a layout.
const styles = StyleSheet.create({
container: {
gap: 15
}
});
It can make layouts easier to read because spacing can be defined in one place.
The rowGap property controls spacing between rows
of children.
const styles = StyleSheet.create({
container: {
rowGap: 15
}
});
It is useful when arranging multiple elements vertically or in wrapped layouts.
The columnGap property controls spacing between
columns of children.
const styles = StyleSheet.create({
container: {
columnGap: 15
}
});
It can be useful for horizontally arranged components.
Flexbox properties such as justifyContent and
alignItems can also help position components.
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
}
});
Flexbox controls positioning, while padding and margin provide additional spacing.
justifyContent: 'space-between' distributes available
space between children along the main axis.
const styles = StyleSheet.create({
container: {
flexDirection: 'row',
justifyContent: 'space-between'
}
});
This is useful for layouts such as headers with content on opposite sides.
A spacing system uses a small set of reusable values throughout the application.
const spacing = {
xs: 4,
sm: 8,
md: 16,
lg: 24,
xl: 32
};
You can then reuse these values in component styles.
const spacing = {
sm: 8,
md: 16,
lg: 24
};
const styles = StyleSheet.create({
card: {
padding: spacing.md,
marginBottom: spacing.lg
},
title: {
marginBottom: spacing.sm
}
});
Reusable spacing values help maintain consistency across screens.
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 20
},
header: {
marginBottom: 25
},
section: {
marginBottom: 20
},
footer: {
marginTop: 30
}
});
Different spacing values can separate major sections of a screen.
Mobile devices have different screen sizes. Good spacing should work well across different devices.
const styles = StyleSheet.create({
container: {
flex: 1,
paddingHorizontal: 20
},
content: {
marginVertical: 15
}
});
Flexbox and relative layouts are generally more flexible than depending on fixed screen dimensions.
Safe-area handling and normal component spacing solve different layout problems. Safe-area insets help keep content away from unsafe screen regions, while padding and margin control the spacing of the content itself.
<SafeAreaView
style={styles.container}
>
<View style={styles.content}>
<Text>
Welcome
</Text>
</View>
</SafeAreaView>
const styles = StyleSheet.create({
container: {
flex: 1
},
content: {
padding: 20
}
});
import React from 'react';
import {
View,
Text,
TextInput,
Pressable,
StyleSheet
} from 'react-native';
const spacing = {
sm: 8,
md: 16,
lg: 24
};
export default function App() {
return (
<View style={styles.container}>
<Text style={styles.title}>
Student Registration
</Text>
<Text style={styles.label}>
Name
</Text>
<TextInput
style={styles.input}
placeholder="Enter your name"
/>
<Text style={styles.label}>
Email
</Text>
<TextInput
style={styles.input}
placeholder="Enter your email"
/>
<Pressable
style={styles.button}
>
<Text style={styles.buttonText}>
Register
</Text>
</Pressable>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
padding: spacing.lg,
justifyContent: 'center'
},
title: {
fontSize: 26,
fontWeight: 'bold',
textAlign: 'center',
marginBottom: spacing.lg
},
label: {
fontSize: 16,
fontWeight: '600',
marginBottom: spacing.sm
},
input: {
borderWidth: 1,
borderColor: '#CBD5E1',
borderRadius: 8,
padding: 12,
marginBottom: spacing.md
},
button: {
backgroundColor: '#2563EB',
paddingVertical: 14,
borderRadius: 8,
alignItems: 'center',
marginTop: spacing.sm
},
buttonText: {
color: '#FFFFFF',
fontSize: 16,
fontWeight: 'bold'
}
});
This example uses padding, margins and reusable spacing constants to create a simple registration form.
gap where appropriate for child spacing.Create Screen
↓
Set Container Padding
↓
Create Sections
↓
Add Internal Padding
↓
Add Margins Between Sections
↓
Use Flexbox
↓
Use Gap When Appropriate
↓
Create Consistent Spacing
↓
Test Different Screen Sizes
↓
Improve Layout
Spacing is a fundamental part of mobile UI design. By combining padding, margin, gap and Flexbox correctly, you can create clean, comfortable and professional React Native interfaces.
padding creates space inside a component.margin creates space outside a component.paddingTop, paddingBottom,
paddingLeft and paddingRight control
individual padding sides.marginTop, marginBottom,
marginLeft and marginRight control
individual margin sides.paddingHorizontal and paddingVertical
simplify two-direction spacing.marginHorizontal and marginVertical
simplify two-direction spacing.gap can create spacing between children.rowGap and columnGap provide directional
gap control.Question: Which property creates space inside a React Native component?