material-ui > Paper
Material UI Paper Component - Examples
Material UI Paper Component CSS
The Paper component is very simple. It is a single <div>
with some React props that map to CSS properties.
As we'll show below, not all CSS props are available as React props, and most of the time we will be adding CSS via
the className
prop to customize the border or backgroundColor. The key prop to note is the elevation
prop, which
sets the box-shadow
to theme.shadows[number]
defined in the Material UI default styles. For other props, see the
links below for the API and check out the short source code for this component.
Paper Background Color
To set a background color on Material UI's Paper, you simply need to apply the background-color
CSS property to the
root element of the Paper. Setting the styles on the root element of any Material UI component can be done in multiple ways,
but the most common is to use the useStyles
hook. As you can see in the example above, we create our CSS classes, defining
a yellowPaper
class which sets a backgroundColor
to be Material UI's yellow color. Then, simply applying that one class
to our <Paper>
component via the className
prop, the classes are applied to the root Paper element, which is the <div>
representing the Paper. This component is only one <div>
, so it is quite a simple component.
Paper Padding
By default there is no padding on the Paper component. However, you can add it pretty easily yourself in 2 ways. One way
(not implemented in above example) would be to use the className prop used above to implement padding via a new
CSS prop padding: theme.spacing(3)
. Another, as shown in above Sandbox, is by importing a Box
component and
using the shorthand system property p={3}
.
Paper Width and Height
The Paper component has no width or height properties. It behaves like a normal <div>
element, because that's what it is, a single <div>
with a few
CSS properties. In the above example, you can see we target all children of the container to have width/height
of theme.spacing(...)
. This was
how Material UI sized the Paper elements in their example.
Paper Elevation
The Paper's elevation
prop simply maps Material UI's theme.shadows
to box-shadow
based on the number. The range is from 0
to 24, where 0 is box-shadow: none
and 24 is shadow of around 40px. You can see the full list of shadows in the
default theme.
Paper Border Color
By default, the Paper component uses an elevation (box-shadow) of 1 and no border. If you set the variant
prop to
be 'outlined'
, you will get a border of 1px solid ${theme.palette.divider}
. If you want to fully customize the
border, you can use CSS classes to style the border on the root Paper element. See the above example, where we apply our
own custom border.
Paper border radius / square prop
By default, the Paper has a border-radius of theme.shape.borderRadius
which is 4px. If you want to customize the
border radius, you can create a CSS property on a custom class to set the border radius on the root component. If you
set the square
prop to true, the border-radius will be set to 0
. See above examples for how we implement these.
🛈 React School creates templates and video courses for building beautiful apps with React. Download our free Material UI template.