Online Forum To Support Coders With Technical Assistance - Read Write Execute

How to align a div in center?

Aman Agrawal
Aman Agrawal
Published on July 4, 2015 · 1 min read

While aligning the div we have problem to aligning a div in center. Using margin according to page and then readjustment is cumbersome and not an efficient method.

Instead use below code in your CSS:-

<div class="center"></div>

<style>
.center
{
    margin-left:auto;
    margin-right:auto;
}

</style> 

 
Was this article helpful?
Aman Agrawal

Aman Agrawal

Author & Senior Engineer at CodeExecute

Writing practical engineering guides, debugging real-world bottlenecks, and creating free tools for developer productivity.

← Previous Article How to remove outline from input tag Next Article → How to get latitude and longitude from address in php