CSS: Alignment tips

CSS: Alignment tips


Now that we've covered the most common CSS properties, here is a summary to how to center an element.


Text inside block level elements can be aligned with text-align.

h1 {
   /* Possible values are : left, right, center, justified*/
   text-align: center; 


Another common technique for center alignement in block level elements is to use margin: 0 auto, as explained in Margins chapter.


To align an element with respect to the viewport or its containing element, you can use absolute position with left, right, top, bottom properties. See Positionning chapter.


You can align an element left or right inside its container with float:left (or right). See Float chapter.