26
0

Center Anything Horizontally with CSS

26
0
<div class="container">
        <h1>HEy Welcome to the Coding!</h1>
    </div>
/* !1st Way using text-align:center  */
.container h1{
    text-align: center;
}

/* ! 2nd way using margin:auto  + width  */
.container h1 {
    width: max-content;
    margin: 0 auto;
}

/* ! 3rd way using flexbox  */
.container{
    display: flex;
    justify-content: center;
}

Leave a Reply

Your email address will not be published.