# Material-UI v4
Material-UI v4 is a popular React component library that implements Google's Material Design specification. This version (v4.11.3) uses the `@material-ui/core` package naming convention and JSS (JavaScript Style Sheets) as its default styling solution. It provides a comprehensive set of production-ready components that are accessible, customizable, and well-documented. Material-UI v4 has been battle-tested in countless production applications and offers a stable foundation for building React applications with Material Design aesthetics.
This is the legacy version 4 of Material-UI, which has been superseded by v5 (now called MUI). While v4 is in maintenance mode with only critical bug fixes and security patches, it remains widely used in production applications. The library requires React 16.8+ or React 17, uses JSS for styling, and includes packages for core components (`@material-ui/core`), styling utilities (`@material-ui/styles`), system utilities (`@material-ui/system`), icons (`@material-ui/icons`), and experimental components (`@material-ui/lab`).
## Installation
Install Material-UI v4 core package
```bash
# Using npm
npm install @material-ui/core
# Using yarn
yarn add @material-ui/core
# Install Roboto font (optional but recommended)
npm install typeface-roboto
# Install Material Icons (optional)
npm install @material-ui/icons
# Peer dependencies required
# React: ^16.8.0 || ^17.0.0
# React DOM: ^16.8.0 || ^17.0.0
```
## Basic Button Component Usage
Create and use Material-UI v4 buttons with different variants
```jsx
import React from 'react';
import Button from '@material-ui/core/Button';
function App() {
return (
);
}
export default App;
```
## Layout with Box, Container, and Grid
Use layout components for responsive designs
```jsx
import React from 'react';
import Container from '@material-ui/core/Container';
import Box from '@material-ui/core/Box';
import Grid from '@material-ui/core/Grid';
import Paper from '@material-ui/core/Paper';
import Typography from '@material-ui/core/Typography';
export default function LayoutExample() {
return (
Welcome to Material-UI v4
Main content area (8 columns on medium+, full width on small)
Sidebar (4 columns on medium+, full width on small)
);
}
```
## Form Controls with TextField
Create form inputs with validation
```jsx
import React, { useState } from 'react';
import TextField from '@material-ui/core/TextField';
import Button from '@material-ui/core/Button';
import Box from '@material-ui/core/Box';
export default function FormExample() {
const [email, setEmail] = useState('');
const [error, setError] = useState(false);
const handleSubmit = (event) => {
event.preventDefault();
const isValid = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
setError(!isValid);
if (isValid) {
console.log('Form submitted:', email);
}
};
return (
setEmail(e.target.value)}
error={error}
helperText={error ? 'Please enter a valid email' : ''}
margin="normal"
required
/>
);
}
```
## Custom Theme with makeStyles and ThemeProvider
Define and apply custom themes using JSS
```jsx
import React from 'react';
import { createMuiTheme, ThemeProvider } from '@material-ui/core/styles';
import { makeStyles } from '@material-ui/core/styles';
import CssBaseline from '@material-ui/core/CssBaseline';
import Button from '@material-ui/core/Button';
import Typography from '@material-ui/core/Typography';
import Box from '@material-ui/core/Box';
const theme = createMuiTheme({
palette: {
primary: {
main: '#1976d2',
light: '#42a5f5',
dark: '#1565c0',
},
secondary: {
main: '#dc004e',
},
},
typography: {
fontFamily: '"Roboto", "Helvetica", "Arial", sans-serif',
h1: {
fontSize: '2.5rem',
fontWeight: 500,
},
},
overrides: {
MuiButton: {
root: {
borderRadius: 8,
textTransform: 'none',
},
},
},
});
const useStyles = makeStyles((theme) => ({
root: {
padding: theme.spacing(4),
},
customButton: {
marginTop: theme.spacing(2),
background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)',
border: 0,
color: 'white',
height: 48,
padding: '0 30px',
boxShadow: '0 3px 5px 2px rgba(255, 105, 135, .3)',
},
}));
export default function ThemeExample() {
const classes = useStyles();
return (
Custom Themed App
);
}
```
## Card Component with Actions
Create content cards with headers, media, and actions
```jsx
import React from 'react';
import Card from '@material-ui/core/Card';
import CardActions from '@material-ui/core/CardActions';
import CardContent from '@material-ui/core/CardContent';
import CardMedia from '@material-ui/core/CardMedia';
import CardHeader from '@material-ui/core/CardHeader';
import Avatar from '@material-ui/core/Avatar';
import IconButton from '@material-ui/core/IconButton';
import Button from '@material-ui/core/Button';
import Typography from '@material-ui/core/Typography';
import { red } from '@material-ui/core/colors';
import MoreVertIcon from '@material-ui/icons/MoreVert';
export default function CardExample() {
return (
R
}
action={
}
title="Recipe Title"
subheader="September 14, 2021"
/>
This impressive recipe combines the flavors of shrimp and
chorizo with smoked paprika, creating a truly delicious dish.
);
}
```
## Dialog (Modal) Component
Display modal dialogs with customizable content
```jsx
import React, { useState } from 'react';
import Button from '@material-ui/core/Button';
import Dialog from '@material-ui/core/Dialog';
import DialogActions from '@material-ui/core/DialogActions';
import DialogContent from '@material-ui/core/DialogContent';
import DialogContentText from '@material-ui/core/DialogContentText';
import DialogTitle from '@material-ui/core/DialogTitle';
import TextField from '@material-ui/core/TextField';
export default function DialogExample() {
const [open, setOpen] = useState(false);
const handleOpen = () => setOpen(true);
const handleClose = () => setOpen(false);
const handleSubmit = () => {
console.log('Form submitted');
handleClose();
};
return (
);
}
```
## AppBar and Navigation
Build application headers with navigation menus
```jsx
import React, { useState } from 'react';
import AppBar from '@material-ui/core/AppBar';
import Toolbar from '@material-ui/core/Toolbar';
import Typography from '@material-ui/core/Typography';
import Button from '@material-ui/core/Button';
import IconButton from '@material-ui/core/IconButton';
import Menu from '@material-ui/core/Menu';
import MenuItem from '@material-ui/core/MenuItem';
import MenuIcon from '@material-ui/icons/Menu';
import { makeStyles } from '@material-ui/core/styles';
const useStyles = makeStyles((theme) => ({
root: {
flexGrow: 1,
},
menuButton: {
marginRight: theme.spacing(2),
},
title: {
flexGrow: 1,
},
}));
export default function AppBarExample() {
const classes = useStyles();
const [anchorEl, setAnchorEl] = useState(null);
const handleMenu = (event) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};
return (
This component uses the makeStyles hook for styling with theme support.
);
}
```
## Summary
Material-UI v4 provides a mature and stable component library for building React applications with Material Design. While it is now in maintenance mode (superseded by MUI v5), it remains an excellent choice for existing projects and offers a comprehensive set of components including Buttons, TextFields, Dialogs, Tables, Cards, Grids, and more. The library uses JSS for styling through APIs like `makeStyles`, `withStyles`, and `styled`, providing a powerful theming system through `createMuiTheme` and `ThemeProvider`. The `@material-ui/lab` package contains experimental components like Alert, Autocomplete, Rating, and Skeleton that are production-ready but may have API changes in future releases.
Key advantages of Material-UI v4 include its extensive component library, TypeScript support, comprehensive documentation, responsive design utilities with breakpoints, built-in accessibility features, and the flexibility of the JSS styling solution. Common use cases include enterprise dashboards, admin panels, e-commerce platforms, data-heavy applications, and form-intensive web apps. The library integrates well with React frameworks, supports server-side rendering, and has a large community with extensive third-party resources. For new projects, consider migrating to MUI v5, but Material-UI v4 remains a solid choice for maintaining existing applications with continued security updates and critical bug fixes.