What is the CSS box model?
Every element is a box made of content, padding, border and margin. The default content-box size counts only the content; border-box includes padding and border in the width you set.
All levels 路 All roles 路 All technologies
Every question in one place. Combine filters to narrow the list, or search for a concept, such as closure, JOIN, useEffect or rate limiter.
7 of 169 questions match
Clear filtersEvery element is a box made of content, padding, border and margin. The default content-box size counts only the content; border-box includes padding and border in the width you set.
display: none removes the element from the layout so it takes no space; visibility: hidden hides it but leaves the empty space, and the element can still be read in the accessibility tree in some cases.
Block elements start on a new line and take the full available width; inline elements sit in the text flow and ignore width and height; inline-block sits in the flow but accepts width, height, padding and margin on all sides.
em is relative to the parent font size, rem is relative to the root font size, % is relative to the parent鈥檚 relevant size, and vh/vw are 1% of the viewport height or width.
Relative offsets an element from its normal place; absolute positions it against the nearest positioned ancestor; fixed is against the viewport; sticky sits in normal flow until a scroll threshold, then sticks.
Flexbox is one-dimensional (a row or a column). CSS Grid is two-dimensional (rows and columns at once). Use Flexbox for alignment along a line; use Grid when the layout is a real 2D structure.
Specificity is the score the browser uses to decide which rule wins: inline styles beat IDs, IDs beat classes/attributes/pseudo-classes, and those beat elements. When scores tie, the last rule in the source wins.