Skip to content

Centering a div inside another div

Centering divs in other containers it’s tricky for a lot of newbies. Below you will find the quickest and easiest way to center a div inside another div.

<div style=”width:100%”>
<div style=”width:100px; margin:auto”>Center text</div>

Notice I added 100% width to the parent div so it will be as wide as the browser screen. After that, the child div needs two things to be centered:

  1. A width. It can be in percent or pixel, doesn’t matter;
  2. Needs to have left and right margin set to auto;

This is it.

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *