The CSS box model describes the rectangular boxes that are generated for elements in the document tree and laid out according to the visual formatting model. Each box has a content area (e.g. text, an image, etc.) and optional surrounding padding, border, and margin areas.
The CSS box model is responsible for calculating:
The box model has the following rules:
width, height, padding, borders, and margins.height is specified, a block element will be as high as the content it contains, plus padding (unless there are floats, for which see below).width is specified, a non-floated block element will expand to fit the width of its parent minus padding.height of an element is calculated by the content's height.width of an element is calculated by the content's width.paddings and borders are not part of the width and height of an element.Adapted from the Front End Interview Handbook by Yangshun Tay and contributors (MIT License). Source
Spotted a mistake or a rights concern? Report an issue