Skip to content
Related Articles

Related Articles

Improve Article
How to horizontally center a div using CSS?
  • Last Updated : 17 May, 2021

To Horizontally 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 :