Typography is Material-UI component to present your design and content as clearly and efficiently as possible.

Typography with Material-UI

Typography is a Material-UI component to present your design and content as clearly and efficiently as possible.

Typography is a Material-UI component to present your design and content as clearly and efficiently as possible. In this blog, you are going to learn about the Typography component of Material-UI.

This blog is part of the Material-UI basics video series on Cules Coding YouTube channel.

Watch the video about Material-UI Typography:

Watch the full video series Material-UI basics

What is a Typography component?

Typography is simply a component that handles the text-based content of your application like paragraphs, headers, etc.

Usage

It is a very easy use Typography component. Just import and insert on your application.

1import React from 'react'
2import Typography from '@material-ui/core/Typography'
3
4const Text = () => {
5 return (
6 <div>
7 <Typography>This is a Typography component.</Typography>
8 </div>
9 )
10}
11
12export default Text

It will give you a body1 text.

Apply styles to Typography with variant Prop

Variant Prop will allow you use different type of style like h1, h2, body2, subtitle1, subtitle2, caption etc.

1import React from 'react'
2import Typography from '@material-ui/core/Typography'
3
4const Text = () => {
5 return (
6 <div>
7 <Typography>This is a Typography component.</Typography>
8 <Typography variant='h1'>This a H1 text</Typography>
9
10 <Typography variant='body2'>This a body2 text</Typography>
11
12 </div>
13 )
14}
15
16export default Text

Change tags with component prop.

Suppose you want to use the h1 tag but want to use the h5 style. You can easily do it with Component Prop

1import React from 'react'
2import Typography from '@material-ui/core/Typography'
3
4const Text = () => {
5 return (
6 <div>
7 <Typography>This is a Typography component.</Typography>
8 <Typography variant='h1'>This a H1 text</Typography>
9
10 <Typography variant='body2'>This a body2 text</Typography>
11
12 <Typography component='h1' variant='h5'>
13 This a h5 text
14 </Typography>
15
16 </div>
17 )
18}
19
20export default Text

You can also use react component

1import React from 'react'
2import Typography from '@material-ui/core/Typography'
3
4const Text = () => {
5 return (
6 <div>
7 <Typography>This is a Typography component.</Typography>
8 <Typography variant='h1'>This a H1 text</Typography>
9
10 <Typography variant='body2'>This a body2 text</Typography>
11
12 <Typography component='h1' variant='h5'>
13 This a h5 text
14 </Typography>
15
16 <Typography component={Button}>This a h5 text</Typography>
17 </div>
18 )
19}
20
21export default Text

We have used material-UI Button as a component

Change colors

You can change colors with color props. Check the documentation for the color values

1import React from 'react'
2import Typography from '@material-ui/core/Typography'
3
4const Text = () => {
5 return (
6 <div>
7 <Typography>This is a Typography component.</Typography>
8 <Typography variant='h1'>This a H1 text</Typography>
9
10 <Typography variant='body2'>This a body2 text</Typography>
11
12 <Typography component='h1' variant='h5'>
13 This a h5 text
14 </Typography>
15
16 <Typography component={Button}>This a h5 text</Typography>
17
18 <Typography color='primary' variant='h1'>
19 This a Primary text
20 </Typography>
21 <Typography color='secondary' variant='h1'>
22 This a Secondary text
23 </Typography>
24 <Typography color='error' variant=h1'>
25 This a Error text
26 </Typography>
27 </div>
28 )
29}
30
31export default Text

Align text

You can easily align text with the align prop.

1import React from 'react'
2import Typography from '@material-ui/core/Typography'
3
4const Text = () => {
5 return (
6 <div>
7 <Typography>This is a Typography component.</Typography>
8 <Typography variant='h1'>This a H1 text</Typography>
9
10 <Typography variant='body2'>This a body2 text</Typography>
11
12 <Typography component='h1' variant='h5'>
13 This a h5 text
14 </Typography>
15
16 <Typography component={Button}>This a h5 text</Typography>
17
18 <Typography color='primary' variant='h1'>
19 This a Primary text
20 </Typography>
21 <Typography color='secondary' variant='h1' align='center'>
22 This a Centered aligned Secondary text
23 </Typography>
24 <Typography color='error' variant='h1' align='right'>
25 This a Error text
26 </Typography>
27
28 </div>
29 )
30}
31
32export default Text

So, that's it for today. Watch my video about typography. If you have any questions, please comment down below.
If you want to reach out to me, You can follow me on any social media as @thatanjan. Until then stay safe and goodbye. '

Shameless Plug

I have made an Xbox landing page clone with React and Styled components. I hope you will enjoy it. Please consider like this video and subscribe to my channel.

That's it for this blog. I have tried to explain things simply. If you get stuck, you can ask me questions.

Contacts

Blogs you might want to read:

Videos might you might want to watch:

Previous PostWhat is CSS in JS?
Next Post13 reasons why you should use Nextjs