Align div in center Using CSS | Code

Center div

An absolutely positioned element acts the same for distribution of free space, and similarly can be centered vertically at the specified top and bottom.

The trick of aligning div in the center: (The best and most flexible way example code).


Align div in center Using CSS

Note: only works if your element has a fixed height.

How to horizontally center a <div>

With flex-box, it is very easy to style the div horizontally and vertically centered in HTML.

To align the div vertically centered also, use property align-items: center.


How to horizontally center div

Note: The All HTML Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.