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'34const Text = () => {5 return (6 <div>7 <Typography>This is a Typography component.</Typography>8 </div>9 )10}1112export 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'34const Text = () => {5 return (6 <div>7 <Typography>This is a Typography component.</Typography>8 <Typography variant='h1'>This a H1 text</Typography>910 <Typography variant='body2'>This a body2 text</Typography>1112 </div>13 )14}1516export 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'34const Text = () => {5 return (6 <div>7 <Typography>This is a Typography component.</Typography>8 <Typography variant='h1'>This a H1 text</Typography>910 <Typography variant='body2'>This a body2 text</Typography>1112 <Typography component='h1' variant='h5'>13 This a h5 text14 </Typography>1516 </div>17 )18}1920export default Text
You can also use react component
1import React from 'react'2import Typography from '@material-ui/core/Typography'34const Text = () => {5 return (6 <div>7 <Typography>This is a Typography component.</Typography>8 <Typography variant='h1'>This a H1 text</Typography>910 <Typography variant='body2'>This a body2 text</Typography>1112 <Typography component='h1' variant='h5'>13 This a h5 text14 </Typography>1516 <Typography component={Button}>This a h5 text</Typography>17 </div>18 )19}2021export 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'34const Text = () => {5 return (6 <div>7 <Typography>This is a Typography component.</Typography>8 <Typography variant='h1'>This a H1 text</Typography>910 <Typography variant='body2'>This a body2 text</Typography>1112 <Typography component='h1' variant='h5'>13 This a h5 text14 </Typography>1516 <Typography component={Button}>This a h5 text</Typography>1718 <Typography color='primary' variant='h1'>19 This a Primary text20 </Typography>21 <Typography color='secondary' variant='h1'>22 This a Secondary text23 </Typography>24 <Typography color='error' variant=h1'>25 This a Error text26 </Typography>27 </div>28 )29}3031export default Text
Align text
You can easily align text with the align
prop.
1import React from 'react'2import Typography from '@material-ui/core/Typography'34const Text = () => {5 return (6 <div>7 <Typography>This is a Typography component.</Typography>8 <Typography variant='h1'>This a H1 text</Typography>910 <Typography variant='body2'>This a body2 text</Typography>1112 <Typography component='h1' variant='h5'>13 This a h5 text14 </Typography>1516 <Typography component={Button}>This a h5 text</Typography>1718 <Typography color='primary' variant='h1'>19 This a Primary text20 </Typography>21 <Typography color='secondary' variant='h1' align='center'>22 This a Centered aligned Secondary text23 </Typography>24 <Typography color='error' variant='h1' align='right'>25 This a Error text26 </Typography>2728 </div>29 )30}3132export 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
- Email: thatanjan@gmail.com
- LinkedIn: @thatanjan
- Portfolio: anjan
- Github: @thatanjan
- Instagram : @thatanjan
- Twitter: @thatanjan
Blogs you might want to read:
- Eslint, prettier setup with TypeScript and react
- What is Client-Side Rendering?
- What is Server Side Rendering?
- Everything you need to know about tree data structure
- 13 reasons why you should use Nextjs
- Beginners guide to quantum computers
Videos might you might want to watch: