CSS Margins

Estimated reading: 1 minute 61 views

Inherited: No

As you may have guessed, the margin property declares the margin
between an (X)HTML element and the elements around it. The margin
property can be set for the top, left, right and bottom of an element.
(see example below)

				
					margin-top: length percentage or auto; 
margin-left: length percentage or auto;
 margin-right: length percentage or auto;
 margin-bottom: length percentage or auto;
				
			

You can also declare all the margins of an element in a single property as follows

				
					 margin: 10px 10px 10px 10px;

				
			

 If you declare all 4 values as I have above, the order is as follows:
1. top
2. right
3. bottom
4. left

If you only declare two or three values, the undeclared values are taken from the opposing side. (see below)

				
					 margin: 10px 10px; /* 2 values */
 margin: 10px 10px 10px; /* 3 values */
				
			
Share this Doc

CSS Margins

Or copy link