Skip to main content
InterviewHubPRO
Section Overview
Q1

Question 1 of 50

Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

2%
CSS3 & Modern Layouts (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

What is the CSS Box Model (`content-box` vs. `border-box`)?

junior LevelCode ExamplecssBasic

In Simple Words: Every element in CSS is represented as a rectangular box consisting of four concentric layers:

  1. Content: The inner text, image, or child elements.
  2. Padding: Transparent space between content and border.
  3. Border: The line surrounding padding and content.
  4. Margin: Transparent space outside the border separating the element from neighbors.
lua
+-------------------------------------------------------+
| Margin                                                |
|   +-----------------------------------------------+   |
|   | Border                                        |   |
|   |   +---------------------------------------+   |   |
|   |   | Padding                               |   |   |
|   |   |   +-------------------------------+   |   |   |
|   |   |   | Content (width x height)      |   |   |   |
|   |   |   +-------------------------------+   |   |   |
|   |   +---------------------------------------+   |   |
|   +-----------------------------------------------+   |
+-------------------------------------------------------+

content-box (Legacy Browser Default):

  • width applies only to the content area. Adding padding: 20px and border: 5px makes the rendered element wider than the declared width ($200 + 40 + 10 = 250\text{px}$).

border-box (Universal Modern Standard):

  • width includes content + padding + border. An element with width: 200px stays exactly 200px wide regardless of padding or border values.
css
/* Universal production reset */
*, *::before, *::after {
  box-sizing: border-box;
}