DEV Community

Dhairya Shah
Dhairya Shah

Posted on

Center Text in just Two Lines of CSS

Using Flexbox

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

Using Grid

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

So simple 😀

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

Top comments (3)

Collapse
 
azlan_syed profile image
Azlan-Syed

cool

Collapse
 
dhairyashah profile image
Dhairya Shah

Thank you 🙂

Collapse
 
afif profile image
Temani Afif

can you please remove the JS tag?