Learn how to import and style Joy UI components to build a simple login page with light and dark modes.
This tutorial will walk you through how to assemble the UI for a basic login page using Joy UI.
You'll be introduced to several common components as well as some of the props you can use to control their styles.
You'll also encounter key features of Joy UI such as global variants, the `sx` prop, and the `useColorScheme` hook.
By the end, you should understand how to:
1. import and customize Joy UI components
2. add styles to Joy UI components with `sx`
3. override default HTML elements with `component`
4. toggle light and dark mode with `useColorScheme`
## Interactive demo
Here's what the final product looks like—click on the "Show code" button underneath the demo to see the full source code:
{{"demo": "LoginFinal.js", "iframe": true, "isolated": true, "height": 500, "bg": "outlined"}}
## Prerequisites
This tutorial assumes that you've already:
- set up a React app—try [Create React App](https://create-react-app.dev/) if you need a boilerplate
- installed Joy UI in your app—see [Installation](/joy-ui/getting-started/installation/) for instructions
## Import the Sheet component for structure
The [Sheet](/joy-ui/react-sheet/) component is a `
` container that supports Joy UI's [global variants feature](/joy-ui/main-features/global-variants/), helping to ensure consistency across your app.
Import Sheet and add it to your app as shown below.
(If you're using Create React App, for example, all of this code should go in `App.js`.)
```jsx
import * as React from 'react';
import { CssVarsProvider } from '@mui/joy/styles';
import Sheet from '@mui/joy/Sheet';
export default function App() {
return (
Welcome!
);
}
```
:::success
Try playing around with different `variant` values to see the available styles.
In addition to `outlined`, you can also use `solid`, `soft`, or `plain`—these are Joy UI's [global variants](/joy-ui/main-features/global-variants/), and they're available on all components.
:::
### Add styles with the sx prop
All Joy UI components accept [the `sx` prop](/system/getting-started/the-sx-prop/), which gives you access to a shorthand syntax for writing CSS.
It's great for creating one-off customizations or rapidly experimenting with different styles.
Replace your basic Sheet from the previous step with the following `sx`-styled Sheet:
```jsx
Welcome!
```
:::success
Try changing some of the values for the CSS properties above based on the patterns you observe.
To go deeper, read about the `sx` prop in the [MUI System documentation](/system/getting-started/the-sx-prop/).
:::
## Add text with the Typography component
The [Typography](/joy-ui/react-typography/) component replaces HTML header, paragraph, and span tags to help maintain a consistent hierarchy of text on the page.
The `level` prop gives you access to a pre-defined scale of typographic values.
Joy UI provides 11 typographic levels out of the box.
- Four heading levels: `'h1' | 'h2' | 'h3' | 'h4'`
- Three title levels: `'title-lg' | 'title-md' | 'title-sm'`
- Four body levels: `'body-lg' | 'body-md' | 'body-sm' | 'body-xs'`
Add an import for Typography with the rest of your imports:
```jsx
import Typography from '@mui/joy/Typography';
```
Replace `Welcome!` inside your Sheet component with this `
`:
```jsx
Welcome!
Sign in to continue.
```
:::success
Try changing the values for the `level` and `component` props to see how they affect the typographic values and the elements rendered.
(Note that while `level` only accepts the 11 values listed above, you can pass any HTML tag to `component`, as well as custom React components.)
:::
## Add text field for user inputs
The Form Control, Form Label, and Input components can be used together to provide you with a sophisticated field for user input.
Add imports for Form Control, Form Label, and Input with the rest of your imports:
```jsx
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import Input from '@mui/joy/Input';
```
Insert these two text fields below the `
` from the previous step, inside the Sheet:
```jsx
EmailPassword
```
## Import Button and Link for user actions
The [Button](/joy-ui/react-button/) and [Link](/joy-ui/react-link/) components replace the HTML `