As we saw from the box model, margin is the space outside of the border, and is used to determine spacing among the different elements. In a box, there are four sides. So, we can specify margins up to the 4 sides:
A fifth property, margin, is used as a shortcut for the above four properties.
Margins can be specified in 3 ways: length, percentage, or auto. Let's take a look at an example:
The following HTML
renders the following:
All four margins can be specified on a single line using the margin property. The syntax is as follows:
margin: [margin-top] [margin-right] [margin-bottom] [margin-left]
The order is very important here. The first element is always the top margin, the second is always the right margin, the third is always the bottom margin, and the fourth is always the left margin.