CSS — Box & Borders

When you open a website, HTML elements are rendered using a "box model". Each elements is drawn/displayed inside a box, though we rarely look at it. In fact, this <p> element has its own box.

In short words, each box is delimited by its border. The distance between the box and its content is called the padding, and the distance between the border and the closest element is called the margin. The three of them border, margin and padding, have top, bottom, left and right specifications.

Box Model diagram
Box model digram as seen on MDN.
Element Description Shorthand for...
Margin Distance from the border of the box to and adjacent element. It is measured horizontally from vertical borders and vertically from horizontal borders. margin-top, margin-right, margin-bottom, margin-left
Border The sometimes invisible line that is the edge of the acutal box. For each of the four edges, one can control width, color and style. border-width, border-style, border-color, each of which is a shorthand for its top, bottom, right and left constituents.
Padding A blank space between the border of the box and the content. Can be thought of as an “inner margin”. padding-top, padding-right, padding-bottom, padding-left
Width Actual width of the content.
Height Actual height of the content.