content logo

Learn CSS:

CSS Margin

An element has four sides: right, left, top and bottom. The margin is the distance from each side to the neighboring element (or the borders of the document).

 

The CSS code for this would look as follow:

body {
	margin-top: 100px;
	margin-right: 40px;
	margin-bottom: 10px;
	margin-left: 70px;
}

Or you could choose a more elegant compilation:

body {
	margin: 100px 40px 10px 70px;
}

You can set the margins in the same way on almost every element. For example, we can choose to define margins for all of our text paragraphs marked with <p>:

body {
	margin: 100px 40px 10px 70px;
}

p {
	margin: 5px 50px 5px 50px;
}

 

#

Css Margin Example

#

Css Margin Code

#

Css Margin Tutorial