A Box
is basically a div
* on steroid. Box
allows you to apply dynamic styles to an otherwise normal div
very quickly like inline styles (but it's not inline styles). Besides that, it also has a first-class integration with MUI theme:
<Box
sx={{
bgcolor: 'primary.main',
color: 'text.secondary',
border: 4,
borderRadius: 2,
px: 2,
fontWeight: 'fontWeightBold',
zIndex: 'tooltip',
boxShadow: 8,
}}
>
Box
</Box>
If you need to do the above with a normal div
, you have to get the theme
object using useTheme
hook and create an inline styles which is not a good practice if abused everywhere:
<div
style={{
backgroundColor: theme.palette.primary.main,
color: theme.palette.text.secondary,
border: '4px solid black',
borderRadius: theme.shape.borderRadius * 2,
padding: `0 ${theme.spacing(2)}`,
fontWeight: theme.typography.fontWeightBold,
zIndex: theme.zIndex.tooltip,
boxShadow: theme.shadows[8],
}}
>
div
</div>
Box
among other components like Typography
or Stack
also supports system properties that lets you pass the style values to the top-level props, which resulted in even shorter code. Internally, the system properties are gathered and merged with the sx
prop so they are the same thing (See this answer for more detail)
<Box
bgcolor="primary.main"
color="text.secondary"
border={4}
borderRadius={2}
px={2}
fontWeight="fontWeightBold"
zIndex="tooltip"
boxShadow={8}
>
Box
</Box>
Because Box
leverages sx
prop, you can also use sx
features like adding responsive values:
<Box
display={{
xs: 'none',
sm: 'block',
}}
width={{
sm: 30,
md: 50,
lg: 100,
}}
>
Or creating nested styles:
<Box
display='flex'
sx={{
'& > :not(:last-child)': {
mr: 2 // maginRight: theme.spacing(2)
},
':hover': {
bgcolor: 'green'
}
}}
>
When to use Box
?
- When you want to create a styled
div
quickly when prototyping.
- When you want to create a one-off inline styles that is not really reusable anywhere else. This is convenient when you want to fix something that is a bit off in a specific part of your layout.
- When you want to add dynamic or responsive styles and make your code easier to understand at the same time because everything is defined in one place, plus the fact that
sx
syntax is highly compact.
- When you want to reference multiple MUI theme properties because many
sx
properties are theme-aware out-of-the-box.
When not to use Box
?
- When you don't need to styles anything. Just use a normal
div
then.
- When you are using it in a highly reusable components like list item, grid item or table cell. This is because
sx
prop has the slowest performance (2x slower than the second slowest approach)
- When you're using other MUI components. In v5, all components from MUI has
sx
support so using Box
as a wrapper or root component is unnecessary if you just want to style other MUI components.

*: By default a Box
is a div
, but you can override the root component of it. For example: <Box component='span'>