Skip to content
Related Articles

Related Articles

How to horizontally center a div using CSS?
  • Last Updated : 25 Jun, 2019

To Horizontaly centered the <div> Element :

  • We can use the property of margin set to auto i.e margin:auto;.
  • The <div> Element takes up its specified width and divide equally the remaining space by the left and right margins.


<!DOCTYPE html>
        How to horizontally center
        a div using CSS
        div {
            border: 3px solid green;
        h1, h2{
        It is a computer science portal for
        Geeks. GeeksForGeeks ia a good website
        for learning computer science;


Supported Browsers: The browser supported by margin:auto property are listed below:

  • Apple Safari
  • Google Chrome
  • Firefox
  • Opera
  • Internet Explorer
My Personal Notes arrow_drop_up
Recommended Articles
Page :