Margin Properties








PropertyDescriptionPossible ValuesExamples
margin-topDeclares the top margin for the element.Lengths, percentages, and the predefined value .
div { margin-top:5px; }

div { margin-top:15%; }

margin-rightDeclares the right margin for the element.Lengths, percentages, and the predefined value .
div { margin-right:5px; }

div { margin-right:15%; }

margin-bottomDeclares the bottom margin for the element.Lengths, percentages, and the predefined value .
div { margin-bottom:5px; }

div { margin-bottom:15%; }

margin-leftDeclares the left margin for the element.Lengths, percentages, and the predefined value .
div { margin-left:5px; }

div { margin-left:15%; }

marginShorthand property used to declare all the margin properties at once.Separate values by a space in the following order (those that are not defined will use inherited or default initial values):

margin-top
margin-right
margin-bottom
margin-left

Undeclared values work as further shorthand notation. If only one length value is declared, all four margins will use that length. If two lengths are declared, the top and bottom margins will use the first length while the right and left margins will use the second length. If three lengths are declared, the top margin will use the first length, the right and left margins will use the second length, and the bottom margin will use the third length.

div { margin:5px 12px 4px 7px; }

div { margin:5px; }

div { margin:5px 10px; }

div { margin:5px 7px 4px; }




Back to Learn more About CSS