Display
Quickly and responsively toggle the display value of components and more with the display utilities. Includes support for some of the more common values, as well as some extras for controlling display when printing.
Examples
Inline
inline
inline
import React from 'react';
import Box from '@material-ui/core/Box';
export default function Inline() {
return (
<div style={{ width: '100%' }}>
<Box component="div" display="inline" p={1} m={1} bgcolor="background.paper">
inline
</Box>
<Box component="div" display="inline" p={1} m={1} bgcolor="background.paper">
inline
</Box>
</div>
);
}
<Box component="div" display="inline">inline</Box>
<Box component="div" display="inline">inline</Box>
Block
blockblock
import React from 'react';
import Box from '@material-ui/core/Box';
export default function Block() {
return (
<div style={{ width: '100%' }}>
<Box component="span" display="block" p={1} m={1} bgcolor="background.paper">
block
</Box>
<Box component="span" display="block" p={1} m={1} bgcolor="background.paper">
block
</Box>
</div>
);
}
<Box component="span" display="block">block</Box>
<Box component="span" display="block">block</Box>
Hiding elements
For faster mobile-friendly development, use responsive display classes for showing and hiding elements by device. Avoid creating entirely different versions of the same site, instead hide element responsively for each screen size.
Screen Size | Class |
---|---|
Hidden on all | display="none" |
Hidden only on xs | display={{ xs: 'none', sm: 'block' }} |
Hidden only on sm | display={{ xs: 'block', sm: 'none', md: 'block' }} |
Hidden only on md | display={{ xs: 'block', md: 'none', lg: 'block' }} |
Hidden only on lg | display={{ xs: 'block', lg: 'none', xl: 'block' }} |
Hidden only on xl | display={{ xs: 'block', xl: 'none' }} |
Visible only on xs | display={{ xs: 'block', sm: 'none' }} |
Visible only on sm | display={{ xs: 'none', sm: 'block', md: 'none' }} |
Visible only on md | display={{ xs: 'none', md: 'block', lg: 'none' }} |
Visible only on lg | display={{ xs: 'none', lg: 'block', xl: 'none' }} |
Visible only on xl | display={{ xs: 'none', xl: 'block' }} |
hide on screens wider than md
hide on screens smaller than md
import React from 'react';
import Box from '@material-ui/core/Box';
export default function Hiding() {
return (
<div style={{ width: '100%' }}>
<Box display={{ xs: 'block', md: 'none' }} m={1}>
hide on screens wider than md
</Box>
<Box display={{ xs: 'none', md: 'block' }} m={1}>
hide on screens smaller than md
</Box>
</div>
);
}
<Box display={{ xs: 'block', md: 'none' }}>
hide on screens wider than md
</Box>
<Box display={{ xs: 'none', md: 'block' }}>
hide on screens smaller than md
</Box>
Display in print
Screen Only (Hide on print only)
Print Only (Hide on screen only)
import React from 'react';
import Box from '@material-ui/core/Box';
export default function Print() {
return (
<div style={{ width: '100%' }}>
<Box display="block" displayPrint="none" m={1}>
Screen Only (Hide on print only)
</Box>
<Box display="none" displayPrint="block" m={1}>
Print Only (Hide on screen only)
</Box>
</div>
);
}
<Box display="block" displayPrint="none">
Screen Only (Hide on print only)
</Box>
<Box display="none" displayPrint="block">
Print Only (Hide on screen only)
</Box>
Overflow
Overflow Hidden. Overflow Hidden. Overflow Hidden.
Overflow Auto. Overflow Auto. Overflow Auto.
import React from 'react';
import Box from '@material-ui/core/Box';
export default function Overflow() {
return (
<div style={{ width: 200, whiteSpace: 'nowrap' }}>
<Box component="div" my={2} overflow="hidden" bgcolor="background.paper">
Overflow Hidden. Overflow Hidden. Overflow Hidden.
</Box>
<Box component="div" my={2} overflow="auto" bgcolor="background.paper">
Overflow Auto. Overflow Auto. Overflow Auto.
</Box>
</div>
);
}
<Box component="div" overflow="hidden">
Overflow Hidden
</Box>
<Box component="div" overflow="visible">
Overflow visible
</Box>
Text Overflow
<Box component="div" textOverflow="clip">
Text Overflow Clip
</Box>
<Box component="div" textOverflow="ellipsis">
Text Overflow Ellipsis
</Box>
Visibility
Visibility VisibleVisibility Hidden
import React from 'react';
import Box from '@material-ui/core/Box';
export default function Visibility() {
return (
<div style={{ width: '100%' }}>
<Box component="span" visibility="visible" p={1} m={1} bgcolor="background.paper">
Visibility Visible
</Box>
<Box component="span" visibility="hidden" p={1} m={1} bgcolor="background.paper">
Visibility Hidden
</Box>
</div>
);
}
<Box component="div" visibility="visible">
Visibility Visible
</Box>
<Box component="div" visibility="hidden">
Visibility Hidden
</Box>
White Space
White Space Nowrap. White Space Nowrap.
White Space Normal. White Space Normal.
import React from 'react';
import Box from '@material-ui/core/Box';
export default function WhiteSpace() {
return (
<div style={{ width: 200 }}>
<Box component="div" my={2} whiteSpace="nowrap" bgcolor="background.paper">
White Space Nowrap. White Space Nowrap.
</Box>
<Box component="div" my={2} whiteSpace="normal" bgcolor="background.paper">
White Space Normal. White Space Normal.
</Box>
</div>
);
}
<Box component="div" whiteSpace="nowrap">
White Space Nowrap
</Box>
<Box component="div" whiteSpace="normal">
White Space Normal
</Box>
API
import { display } from '@material-ui/system';
Import name | Prop | CSS property | Theme key |
---|---|---|---|
displayPrint |
displayPrint |
display |
none |
displayRaw |
display |
display |
none |
overflow |
overflow |
overflow |
none |
textOverflow |
textOverflow |
text-overflow |
none |
visibility |
visibility |
visibility |
none |
whiteSpace |
whiteSpace |
white-space |
none |