MUI is a React UI library that provides ready‑made components like buttons, inputs, cards, etc.
import Button from "@mui/material/Button";
export default function App() {
return <Button variant="contained">Click Me</Button>;
}
To create UI faster, look professional, responsive, and avoid writing long CSS.
<TextField label="Email" variant="outlined" />
npm install @mui/material @emotion/react @emotion/styled
MUI gives different button styles using variant and color.
<Button variant="contained">Submit</Button>
<Button variant="outlined" color="secondary">Cancel</Button>
<Button variant="text" color="error">Delete</Button>
It allows quick inline styling inside MUI components.
<Button sx={{ backgroundColor: "green", padding: "10px" }}>Save</Button>
import Box from "@mui/material/Box";
A layout container used for spacing, padding, margin, flex, etc.
<Box sx={{ p: 2, backgroundColor: "#eee" }}>Box Container</Box>
Used to make responsive layouts using a 12‑column system.
import Grid from "@mui/material/Grid";
<Grid container spacing={2}>
<Grid item xs={6}>Left</Grid>
<Grid item xs={6}>Right</Grid>
</Grid>
An input component with built‑in design and label.
<TextField label="Username" fullWidth />
Used to set global colors, fonts, and theme settings for the whole app.
const theme = createTheme({ palette: { primary: { main: "#1976d2" }}});
<ThemeProvider theme={theme}>
<Button>Click</Button>
</ThemeProvider>
Used to create top navigation bars.
<AppBar position="static" >
<Toolbar>My App</Toolbar>
</AppBar>
import HomeIcon from "@mui/icons-material/Home";
<HomeIcon />
CardContent is a Material UI component that provides padding, spacing, and layout for the inside section of a Card.
<Card>
<CardContent>Title</CardContent>
</Card>
You can create custom styled components using MUI’s styled() API.
import { styled } from "@mui/material/styles";
import Button from "@mui/material/Button";
const MyButton = styled(Button)({
backgroundColor: "#0077ff",
padding: "10px 25px",
borderRadius: "10px",
});
<MyButton>Custom Button</MyButton>
Grid can change its size based on breakpoints.
<Grid container spacing={2}>
<Grid item xs={12} sm={6} md={4}>Card 1</Grid>
<Grid item xs={12} sm={6} md={4}>Card 2</Grid>
<Grid item xs={12} sm={6} md={4}>Card 3</Grid>
</Grid>
Dialog is used for popups and modals.
const [open, setOpen] = useState(false);
<Button onClick={() => setOpen(true)}>Open Dialog</Button>
<Dialog open={open} onClose={() => setOpen(false)}>
<DialogTitle>Alert</DialogTitle>
<DialogContent>This is a popup.</DialogContent>
</Dialog>
MUI Box supports flexbox properties directly with sx.
<Box sx={{ display: "flex", gap: 2 }}>
<Button variant="contained">One</Button>
<Button variant="contained">Two</Button>
</Box>
MUI allows you to add your own color palette.
import { ThemeProvider, createTheme } from "@mui/material/styles";
import Button from "@mui/material/Button";
const theme = createTheme({
palette: {
myBlue: { main: "#0077ff" }
}
});
<ThemeProvider theme={theme}>
<Button color="myBlue" variant="contained">Blue</Button>
</ThemeProvider>
MUI icons can be placed inside buttons using startIcon or endIcon.
import SendIcon from "@mui/icons-material/Send";
<Button variant="contained" endIcon={ } >
Send
</Button>
CardMedia helps display images inside a Card.
<Card sx={{ maxWidth: 300 }}>
<CardMedia
component="img"
height="160"
image="https://via.placeholder.com/300"
/>
<CardContent>Sample Image Card</CardContent>
</Card>
AppBar and Toolbar help create a clean navigation bar.
<AppBar position="static">
<Toolbar sx={{ display: "flex", justifyContent: "space-between" }}>
Logo
<Button color="inherit">Login</Button>
</Toolbar>
</AppBar>
Breakpoints help create responsive designs for mobile, tablet, and desktop using preset sizes like xs, sm, md, lg, xl.
<Box sx={{ width: { xs: "100%", sm: "70%", md: "50%" } }}>
Responsive Box
</Box>
useTheme() lets you access the current theme inside components.
const theme = useTheme();
<Box sx={{ color: theme.palette.primary.main }}>
Themed Text
</Box>
MUI allows text to scale automatically based on screen size.
<Typography variant="h4" sx={{ fontSize: { xs: "20px", md: "32px" } }}>
Responsive Heading
</Typography>
You can override default styles using theme.components.
const theme = createTheme({
components: {
MuiButton: {
styleOverrides: {
root: { borderRadius: "12px" }
}
}
}
});
Stack is used to arrange items vertically or horizontally with spacing.
<Stack direction="row" spacing={2}>
<Button>One</Button>
<Button>Two</Button>
</Stack>
Tabs help switch between multiple views.
const [value, setValue] = useState(0);
<Tabs value={value} onChange={(e, v) => setValue(v)}>
<Tab label="Home" />
<Tab label="Profile" />
</Tabs>