Skip to main content

Command Palette

Search for a command to run...

Center Text in just Two Lines of CSS

Published
•1 min read
Center Text in just Two Lines of CSS
D

I am 17 years old and a young passionate and self-taught frontend web developer and have an intention to become a successful developer. I usually write about JavaScript and Web Development and share some tips in the articles.

Using Flexbox

/* Method 1 - Centering DIV using Flexbox */
.div1 h1{
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

Using Grid

/* Method 2 - Center DIV using Grid */
.div2 h1{
    display: grid;
    place-content: center;
}

So simple 😀

And make sure to center(align-mind: center)😜 your focus towards my YouTube Channel

More from this blog

D

Dhairya Shah

119 posts

Center Text in just Two Lines of CSS