How to center align Div using CSS?

Answer

To center align Div using CSS, you can set the text-align style property for the div elements with the value center.

CSS Code

The following is a typical CSS code to center align Div in HTML page using tag name div.

div {
   text-align: center;
}

Examples

We shall go through some working examples on how to center align Div using CSS. In the following examples, you may change the value of text-align and Run the code to visually observe the changes made to the Div elements.

Example 1

You may edit the following code, and click on Run button.

Example 2

You may edit the following code, and click on Run button.