Define the margin of an element with this general attribute. A margin defines the space around an element's border. We have added borders to the example so that you may see the changes in the margin more readily.

Value Description
size px - size in terms of pixels
em - size in terms of the current font size
in - size in terms of inches
cm - size in terms of centimeters
percentage The width of this element will be a percentage of the element it is inside of.
auto The browser will automatically choose the value.


p {margin: 15px; border: 1px solid black; }

h4 {margin: 10px 25px;
border: 1px solid black; }

h5{margin: 0px 15px 10px 33px;
border: 1px solid red;}


This is a paragraph that has a margin of 15 pixels on every side: top, right, bottom, and left.

This header 4 has a top and bottom margin of 10 pixels and a right and left margin of 25 pixels.

This header 5 has a top margin of 0 pixels, a right margin of 15 pixels, a bottom margin of 10 pixels, and a left margin of 33 pixels.

Compatibility Issues:

IE 5.0 - Margins can be buggy.
IE 5.5 - Margins are less buggy than in 5.0.