How to Size and Position the Material-UI (MUI) Dialog Component

Jon Middaugh
The Clever Dev
Published in
5 min readOct 6, 2021

--

The Material-UI (MUI) Dialog component is one of the most challenging MUI components to style. It is composed of a modal, container, and usually several internal dialog components like DialogContent.

It can difficult to position the appropriate subcomponent within Dialog because the Dialog API does not expose a style prop for every subcomponent. However, Material-UI recently released v5, which included a significant update to their styling APIs (and some component APIs).

My goals with this article are:

  1. Successfully set custom size and position for the Dialog component
  2. Explore and hopefully use only MUI v5 styling APIs without relying on v4 makeStyles and useStyles (but I will include code for v4 styling)

A Code Sandbox link with full React code is in the Resources section. Here’s the MUI Dialog component with every prop enabled.

Sizing the MUI Dialog Component

There are three props for directly manipulating the size of the top-most visible element of the dialog component. The topmost element is a Paper component by default, which is how I will refer to it. Another option is to pass styling to the Paper’s sx prop using PaperProps, but I’ll get to that later.

--

--

Jon Middaugh
The Clever Dev

I have been: individual contributor | tech lead | manager | JS boot camp teacher | community college instructor.