Margin and padding
Last updated
Was this helpful?
Last updated
Was this helpful?
All HTML elements can be considered a box, and each box (HTML element) has the properties margin, border, padding and content. Together these properties is called the box model.
The content area is the area that contains the content of the element, e.g. text or image. It can have a background color or an image (an image will hide the background color). Text and images are located inside the content edge. If the CSS box-sizing property is set to default, the properties width, min-width, max-width, height, min-height and max-height control the content size. If you do not specify at least one pair of these properties, the content's size will determine the size.
The padding area extends to the border surrounding the padding. When the content area has a background, color, or image set on it, will be extended into the padding. Text will not be extended. The padding is located inside the padding edge.
The space between the padding and the content edge can be controlled using the padding-top, padding-right, padding-bottom, padding-left and the shorthand padding CSS properties.
The border area extends the padding area to the area containing the borders. It is the area inside the border edge, and its dimensions are defined by the border-width property, or the shorthand border
.
The margin area extends the border area with an empty area used to separate the element from its neighbors. It is the area inside the margin edge, and its dimensions are the margin-box width and the margin-box height.
The size of the margin area is controlled using the CSS properties margin-top
, margin-right
, margin-bottom
, margin-left
, or the shorthand margin
.