eduKatePunggol · Practical learning guide
Find your next learning step
Choose a route through CSS box-sizing to understand the mechanism, check a worked example and plan the next practice.
Full chapter index · Practice and parent questions · How Studying Works
Your child gives a webpage card a width of three hundred pixels, adds comfortable padding, and discovers that it no longer fits where expected. Two cards that should sit together wrap onto separate rows. A form control reaches beyond its container. The student may keep reducing numbers until the page looks acceptable, yet remain unsure why it changed. A better first step is to identify which rectangle the width describes and account for the space around it.
CSS box-sizing controls how specified sizing values relate to an element's content box and border box. With content-box, a definite width sizes the content area and padding and borders are added outside it. With border-box, those padding and border dimensions are included in the specified size, subject to the content box not becoming negative. This guide teaches the arithmetic, its conditions and its practical limits through small webpage exercises. The Punggol tuition framing supports calm family learning; the fictional web projects are examples rather than advertised classes or school syllabus claims.
Begin with the rectangle model if the measurements are unfamiliar. If you already know the basic arithmetic, use the routes on percentages, layout constraints and debugging. The goal is to predict a simple result before inspecting it, then distinguish a sizing-policy problem from wrapping, margins, minimum sizes or overflowing content. One property cannot explain every layout symptom, but understanding its job removes a common source of confusion.
Choose a chapter
Calculate the rectangles · 1–5
Check sizing conditions · 6–11
Apply the layout policy · 12–17
Build and measure · 18–21
A typical CSS element can be understood through four surrounding areas: content, padding, border and margin. Content is the area in which the element's text or other content is laid out. Padding creates space between that content and the border. The border forms another surrounding area. Margin lies outside the border and contributes separation from other boxes under the applicable layout rules.
For the first calculation, use an ordinary block in normal flow with a definite width, fixed pixel padding and borders, and no flex or grid size negotiation. These conditions make the arithmetic easy to inspect. Later chapters explain why the same declaration can participate in a more complicated layout.
Imagine a card containing a short paragraph. Twenty pixels of padding on the left and right keep the text away from the edges. A two-pixel border marks the card's boundary. A margin separates the card from its neighbour. Each layer has a different purpose, so changing one layer to compensate for another can produce a visually plausible but poorly explained result.
Draw the content rectangle first, then add padding, border and margin as labelled surrounding strips. The drawing need not be artistically accurate. Its job is to show that a width declaration must be interpreted in relation to a particular box, and that margins remain outside the border box.
A parent can ask, “Which of these spaces is the number measuring?” That question directs the student's attention to the meaning of the declaration. A student who identifies the sized box can calculate a new example rather than rely on a remembered total from a previous card.
With content-box and a definite width of three hundred pixels, the content area is three hundred pixels wide. If left and right padding are each twenty pixels and left and right borders are each two pixels, the border box is three hundred and forty-four pixels wide.
.card {
box-sizing: content-box;
width: 300px;
padding: 20px;
border: 2px solid #315c49;
}
The horizontal calculation is three hundred plus twenty plus twenty plus two plus two. It counts both sides separately. A frequent mistake is to add the padding only once because the shorthand declaration contains one number. That one number sets padding on all four sides; the horizontal total includes the left and right values.
The result does not include margins. If the card also has ten-pixel margins on both horizontal sides in a simple non-collapsing horizontal arrangement, those margins add another twenty pixels to the space budget. Keep the border-box width and the outer arrangement budget separate rather than calling both “the width”.
Write a measurement table before looking at the browser. Record content width, horizontal padding total, horizontal border total and border-box width. The table makes the sum transparent and gives the learner a prediction to compare with developer tools.
Do not assume that every element in every browser starts with content-box after all styles are applied. User-agent rules, a reset or a component stylesheet can set another value. The example explicitly states content-box so its arithmetic is unambiguous. In debugging, inspect the computed property rather than infer it from a remembered default or from the visual appearance of the card.
Change only box-sizing to border-box while keeping the definite width, padding and border values from the previous example. The three hundred pixels now include the content area, left and right padding and left and right borders. The content area becomes two hundred and fifty-six pixels wide.
.card {
box-sizing: border-box;
width: 300px;
padding: 20px;
border: 2px solid #315c49;
}
The subtraction is three hundred minus forty pixels of horizontal padding minus four pixels of horizontal borders. This calculation gives the content width for the stated simple case. The border box stays at the intended three hundred pixels because the padding and border fit within that size.
The narrower content area can make text wrap onto more lines. That is a real consequence, not a browser error. Border-box makes the outer sizing budget easier to manage in many layouts, but it does not preserve the old content width when padding and borders are added. A design still needs enough room for readable content.
Ask the student to compare two questions: “How wide is the card boundary?” and “How wide is the area available to the text?” Under border-box, the answers are three hundred and two hundred and fifty-six in this example. Giving the same answer to both hides the padding and border relationship.
A useful transfer exercise changes the width to two hundred and eighty while leaving the other values unchanged. The content area becomes two hundred and thirty-six. Then increase the left padding only and recalculate. The learner should account for each side rather than assume every declaration is symmetric. The purpose is to make the rule usable with unfamiliar dimensions.
Keep the declarations identical except for box-sizing and compare the two measurements side by side. A small table is particularly useful because the same number appears in the width declaration but refers to a different sizing box.
| Measurement | content-box | border-box |
|---|---|---|
| Declared width | 300px | 300px |
| Left and right padding total | 40px | 40px |
| Left and right border total | 4px | 4px |
| Content width | 300px | 256px |
| Border-box width | 344px | 300px |
The table assumes a definite width in the simple block example, with no other size constraints changing the used result. It is a teaching comparison, not a promise that every element in every layout will always render at the declared number. Flex negotiation, minimum sizes and intrinsic content can introduce additional rules.
Notice that padding and border values do not disappear under border-box. They remain real areas. The change is where they fit relative to the specified width. This is why setting border-box can solve a budget problem without removing the comfortable space around the text.
For retrieval practice, cover the last two rows and ask the student to recreate them. Then cover the policy labels and ask which column represents each policy. The student should explain the relationship rather than memorise that one total is larger.
Finally, change the border to four pixels on each side. The content-box border width becomes three hundred and forty-eight. The border-box content width becomes two hundred and fifty-two. A student who can update both columns has a working arithmetic model. If they change the padding totals instead, return to the layer drawing and identify exactly which area the new declaration affects.
Border-box includes padding and borders in the specified sizing box. It does not include margins. This distinction explains why a full-width card can still overrun a container when extra horizontal margins are added.
Suppose the containing block provides four hundred pixels of available content width. A simple block has width one hundred percent, border-box sizing and ten-pixel horizontal margins. The percentage width gives a four-hundred-pixel border box under the example's conditions. The two margins still sit outside it, so the horizontal budget reaches four hundred and twenty pixels.
Reducing padding will not repair that margin budget under border-box, because the border box remains four hundred pixels. The content area changes instead. A student who keeps shrinking padding may see little improvement in the outer overflow and misunderstand why the property appears ineffective.
There are several possible design choices. Use the parent's padding to provide inset space, use an auto-sized block whose normal-flow width calculation accounts for margins, or specify a width that deliberately leaves the needed margin space. The best choice depends on the layout rather than a universal instruction to remove every margin.
Vertical margins bring additional rules, including margin collapsing in some normal-flow block situations. Do not reuse a simple horizontal addition model as a complete explanation of all vertical spacing. The important box-sizing point remains: margins are not absorbed into a border-box width or height.
For practice, ask the learner to draw the card's border boundary and then draw its margins outside. Label the four-hundred-pixel width at the border boundary. The picture makes it clear why the additional space is still relevant even though padding and borders are already included.
CHAPTER 6 OF 24 · Check sizing conditions
6. Height follows the same sizing distinction
For a definite height in the same simple box model, content-box sizes the content area and adds vertical padding and borders. Border-box includes those vertical areas within the specified height, provided the dimensions can fit without requiring a negative content box.
.sample {
box-sizing: border-box;
width: 300px;
height: 180px;
padding: 16px;
border: 2px solid #315c49;
}
The content height in this example is one hundred and forty-four pixels: one hundred and eighty minus thirty-two pixels of vertical padding and four pixels of vertical borders. The content width is two hundred and sixty-four pixels. Calculate the two axes separately, even when the shorthand uses the same padding on every side.
A fixed height can still be unsuitable for a text card. More text, a larger font or a narrower content width can require more vertical space than the allotted content area. Border-box does not automatically expand a definite height to make every paragraph comfortable, nor does it make overflowing text disappear.
For many text-heavy learning cards, an automatic height or a carefully chosen minimum height is more flexible than a fixed height. The design should respond to the actual content and accessibility needs. The arithmetic lesson explains the rectangle; the design decision determines whether that rectangle is appropriate.
Ask the student to add a longer paragraph while keeping the fixed height. Observe what changes: line count and overflow may change even though the border-box dimensions do not. This experiment separates the size of the box from the amount of content it must accommodate. It is an important step toward debugging a webpage without assuming every visual symptom comes from an incorrect width.
Real designs do not always use the same padding and border on every side. A card may have a larger left inset for an icon or a thicker bottom border for emphasis. The arithmetic should use the actual values on the relevant axis.
.card {
box-sizing: border-box;
width: 320px;
padding: 12px 24px 18px 16px;
border-left: 3px solid #315c49;
border-right: 1px solid #315c49;
}
The four padding values follow top, right, bottom and left. Horizontally, the padding total is forty pixels, and the border total is four pixels. The content width is two hundred and seventy-six pixels in the simple definite-width case. The top and bottom padding do not enter this horizontal calculation.
Students often remember a formula with “twice the padding”. That shortcut works only when the two relevant sides are equal. The general calculation adds the left and right values individually. The same principle applies vertically with top and bottom.
Use developer tools to inspect expanded longhand values if a shorthand is hard to read. A later rule may also change just one side. The final computed values determine the calculation, not the first shorthand declaration found in a stylesheet.
For practice, create a measurement table with four padding entries and four border entries. Circle the entries that affect width. Then circle a different set for height. This simple selection exercise prevents the student from adding every visible number in the rule. A correct formula is not merely arithmetic accuracy; it depends on choosing the measurements that describe the requested axis.
CHAPTER 8 OF 24 · Check sizing conditions
8. Percentage widths need a containing block
A percentage width is interpreted against the relevant containing block, rather than against whatever rectangle the student happens to notice on screen. For the ordinary block example, use a parent with a known content width so the basis is clear. Then apply box-sizing to determine how the child's padding and borders relate to its percentage size.
If the parent content width is six hundred pixels and the child width is fifty percent, the specified size is three hundred pixels. With content-box, horizontal padding and borders are added to that content width. With border-box, they fit within the three-hundred-pixel border-box target in the simple case.
This is why two fifty-percent content-box cards with padding may exceed the available width. Each begins with a content width equal to half the parent, then grows beyond it at the border boundary. Changing to border-box addresses that part of the budget. It does not account for a gap between the cards or additional margins.
The containing-block rules become more specialised for positioned elements and other layout contexts. A beginner should start with an ordinary parent-child block example, state the basis explicitly and then investigate more advanced cases when the project requires them. Guessing that every percentage always refers to the viewport creates avoidable confusion.
For a practical trace, write three lines: parent content width, percentage result and child border-box width. Under content-box, the third line adds the relevant padding and borders. Under border-box, it remains the percentage result unless other constraints change the used size. This sequence makes the percentage calculation and the box-sizing calculation two distinct steps that can be checked separately.
An ordinary non-replaced block in normal flow with an automatic width often fills the available horizontal space after its padding, borders and margins are accounted for under the applicable width equation. That is different from explicitly declaring width one hundred percent and then adding outer margins.
This distinction matters when a student says that a block already fits correctly without border-box. The student may be observing an auto-width layout, where the browser's width calculation accounts for the surrounding areas, rather than a definite content width that grows when padding is added. The two examples are not contradictory.
Box-sizing is most visibly demonstrated when a definite width or height is declared. With auto sizing, the property may not produce the dramatic change the student expects from the earlier numerical comparison. Inspect the actual declarations and layout context before deciding that the rule was ignored.
A useful experiment places two otherwise similar cards in the same known-width parent. One uses auto width and horizontal margins; the other uses width one hundred percent with the same margins. Compare their border boundaries and explain the difference. Keep flex, grid and absolute positioning out of this first experiment so the normal-flow rule is not obscured.
The lesson is to avoid reducing CSS to a single slogan such as “padding always adds to width” or “border-box always makes it fit”. Both slogans omit the sizing context. A reliable explanation states whether the width is definite, percentage-based or automatic and identifies the rules involved. The student can then choose an appropriate model rather than applying a memorised correction to every box.
CHAPTER 10 OF 24 · Check sizing conditions
10. Use minimum and maximum sizes thoughtfully
Box-sizing also affects how explicit sizing values such as minimum and maximum widths relate to the relevant box. A card with a maximum width still needs an understood sizing policy, padding budget and containing block. The property does not make minimum and maximum constraints irrelevant.
.reading-card {
box-sizing: border-box;
width: 100%;
max-width: 640px;
padding: 24px;
border: 1px solid #cfcabe;
}
In a straightforward block context, this aims for the available percentage width while limiting the border-box width to six hundred and forty pixels. The text receives the remaining content area after padding and borders. It is a useful starting design for readable cards, but its behaviour should still be checked within the actual page layout.
A minimum width that exceeds a small container can cause overflow even with border-box. The property includes padding and borders in the sizing box; it does not cancel a deliberate minimum constraint. If a card refuses to shrink, inspect minimum sizes as well as its width declaration.
Intrinsic minimum sizes can also matter in flex and grid layouts. Those are discussed later. For now, test a known fixed minimum in a narrow parent and observe that the apparent fit problem persists after switching box-sizing. The experiment makes it clear that another rule is controlling the size.
When debugging, list the width, minimum width and maximum width together. A student who sees only width one hundred percent may overlook a minimum width applied by another component rule. Good inspection follows the final set of constraints rather than selecting the declaration that most closely matches the hoped-for explanation.
CHAPTER 11 OF 24 · Check sizing conditions
11. Padding and borders cannot produce negative content
The content box cannot become negative. This gives border-box an important limit when padding and borders alone exceed the specified size. The rendered border box may need to exceed the tiny declared dimension rather than create an impossible negative content area.
Suppose a simple box has width thirty pixels, left and right padding of twenty pixels each, and two-pixel borders on both sides. The padding and border total is forty-four pixels. Subtracting that total from thirty gives minus fourteen, but minus fourteen is not a valid content width. The content area is floored at zero, and the border box must still accommodate the padding and borders.
This case is often overlooked in a beginner explanation that says the border box “always equals width”. The statement needs conditions. In the ordinary example where the declared width is large enough and no other constraints intervene, it is a useful prediction. In the tiny example, the minimum physical areas reveal why the unqualified promise is wrong.
Use a short label or an empty box for this experiment, since text may introduce additional visible overflow. The point is to inspect the geometric areas, not to design a useful thirty-pixel card. Record the content area and border-box size separately.
The practical response is to choose dimensions and padding that make sense together. Do not treat the zero floor as a technique for hiding content or creating a reliable invisible element. A student should learn to recognise an impossible budget and repair the design requirement. Arithmetic can reveal that the chosen numbers conflict; it cannot make a negative content rectangle physically meaningful.
Many projects use border-box as a consistent baseline because it makes explicit outer dimensions easier to budget. A common approach sets the value on the root and makes elements and pseudo-elements inherit it. The inheritance is explicitly declared because box-sizing is not inherited by default.
html {
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: inherit;
}
This pattern lets a component deliberately establish a different sizing policy and have its descendants follow that policy through inheritance. Another common reset assigns border-box directly to all elements and pseudo-elements. Both approaches can support a consistent baseline; the project's conventions should determine which one to use.
Including pseudo-elements matters when they generate boxes that receive padding, borders or definite sizes. Omitting them can leave a decorative or functional box using a different policy from the surrounding component. Nevertheless, the reset is not a substitute for inspecting a particular rendered element.
In an existing website, do not add a global reset casually inside one article or widget. It can change unrelated components. A small standalone learning page can establish its own baseline, while a component in an existing site should use appropriately scoped rules and respect the surrounding design system.
Ask the student which line creates the root policy and which lines distribute it. Then ask whether box-sizing would inherit automatically without the second rule. The answer is no. This exercise teaches the difference between a property's normal inheritance behaviour and an explicit inherit value, which is a useful CSS concept beyond this one property.
CHAPTER 13 OF 24 · Apply the layout policy
13. Scope a component when the page is established
When working inside an existing website, a component can apply its sizing policy within a named wrapper. This keeps the learning example's rules from unexpectedly changing every element on the page. Scope is especially important when the page includes a theme, form plugin or other independent components.
.practice-panel,
.practice-panel *,
.practice-panel *::before,
.practice-panel *::after {
box-sizing: border-box;
}
This rule covers the wrapper and its descendants, including their before and after pseudo-elements. It is a starting policy for the component, not a promise that later rules cannot override it. The cascade still applies, so inspect the final computed value when something behaves differently.
Avoid selectors so broad that they redefine unrelated page layout. A student creating a small card may test it successfully in isolation and then paste its stylesheet into a larger site, where a global rule affects navigation, forms or other articles. The original arithmetic can be correct while the integration choice is inappropriate.
Scope also improves explanation. A reader can identify which part of the page follows the component's policy and which parts use the surrounding site's policy. That boundary makes debugging more focused because the student does not need to reason about the entire document at once.
For practice, place the component beside an unrelated sample box with an explicit content-box rule. Verify that the component policy affects the intended region. Then inspect both computed values. The exercise teaches CSS integration as well as geometry: a useful declaration must apply to the intended element, and a carefully calculated rule has no effect if its selector never matches.
CHAPTER 14 OF 24 · Apply the layout policy
14. Inspect the cascade when the value seems wrong
If a box behaves as though it uses content-box after you wrote border-box, inspect the computed style and the matched rules. The declaration may be overridden, its selector may not match, or the stylesheet may not have loaded. These are application problems rather than errors in the arithmetic.
A later rule of equal precedence can win by source order. A more specific selector, an important declaration or a different cascade layer can also affect the result under CSS's cascade rules. Do not keep changing the width until the underlying style application is understood.
The existing CSS specificity lesson in the series addresses a separate job: deciding which competing selector rules apply. Box-sizing addresses what a sizing value means once the relevant declaration has been resolved. These learning jobs are related, but one does not replace the other.
Use developer tools to select the exact rendered element. Look for the computed box-sizing value, then expand the relevant rule information if available. Also inspect the width, padding and borders actually used. A declaration crossed out in the style panel is not the active basis for your calculation.
For a short exercise, create two rules that deliberately set different sizing policies on the same card. Predict which rule wins under a simple source-order case, then inspect the result. Remove the conflict afterwards. This controlled experiment helps the student separate “the property has a particular meaning” from “this particular rule is currently applied”. Both questions must be answered before a rendered measurement can be explained confidently.
In a flex container, items can grow or shrink according to their flex properties and the available space. A declared width therefore does not necessarily equal the final rendered width. Box-sizing still affects the interpretation of applicable sizing values, but the layout algorithm introduces additional constraints and negotiation.
Two cards with width fifty percent and border-box sizing can still face a budget problem when a gap is added. Their initial sizes already total the parent's width, leaving no room for the gap. Flex shrinking may reduce them, depending on the rules and minimum-size constraints. If shrinking is disabled, the total can overflow instead.
This is why a student should not infer that border-box failed merely because two cards are not exactly half the container after rendering. The final size may reflect flex allocation. Inspect flex-basis, grow, shrink and minimum size as well as width and padding.
For a clearer two-column flex design, allow the flex algorithm to distribute available space rather than hard-code two full halves plus a gap. For example, equal flexible items with an appropriate basis can share the remaining space. The exact rule depends on content and wrapping requirements, so test it in the intended layout.
Keep the first box-sizing arithmetic lab outside flex. Once that model is secure, introduce a flex container and change only one factor, such as gap or shrink. The comparison shows which additional mechanism altered the result. A learner gains much more from identifying that mechanism than from adding border-box repeatedly to descendants in the hope that some selector eventually fixes the page.
CHAPTER 16 OF 24 · Apply the layout policy
16. Grid tracks and gaps have their own budget
Grid layout can allocate columns and gaps explicitly. A two-column grid using fractional tracks allows the gap to be accounted for in the track layout rather than attaching two widths of fifty percent and then discovering that a gap needs extra room. Box-sizing remains useful within each item, but it is not the mechanism that defines the grid tracks.
.task-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 16px;
}
.task-grid > .card {
box-sizing: border-box;
padding: 20px;
border: 1px solid #cfcabe;
}
This is a starting layout for a simple two-column example. The minimum of zero permits the tracks to shrink below certain intrinsic content-based minimums, but long content can still overflow within an item unless its own handling is appropriate. The rule should be tested with realistic content, not only two short labels.
If the container content width is six hundred and sixteen pixels and the gap is sixteen, two equal tracks can each receive three hundred pixels under the simple stated conditions. Each card's padding and borders then fit within its allocated border-box space. The track calculation and the content-area calculation are separate steps.
On a narrow screen, two columns may leave too little reading room. A responsive change to one column can be more useful than merely shrinking text or padding. Box-sizing does not decide when the design should reflow.
Ask the student to calculate available track space after subtracting the gap, then calculate each card's content width after subtracting its horizontal padding and borders. This two-stage reasoning connects the local box model to the parent layout without pretending that either one alone explains the entire page.
CHAPTER 17 OF 24 · Apply the layout policy
17. Long content can overflow a correct box
A box can have the intended border-box width while its content still extends beyond it. A long unbroken token, a wide image, a preformatted code line or an intrinsic minimum can produce overflow. Changing box-sizing does not automatically create line-break opportunities or scale every child.
For text such as a long address or identifier, an appropriate overflow-wrap rule may help the content break. For a responsive image, a maximum width and suitable height handling may help it fit. For code, horizontal scrolling may preserve readable formatting. These are different content policies that should match what the reader needs.
.card {
box-sizing: border-box;
width: 100%;
padding: 20px;
border: 1px solid #cfcabe;
overflow-wrap: anywhere;
}
.card img {
max-width: 100%;
height: auto;
}
The text rule permits breaks that may be useful for otherwise unbreakable strings. The image rule limits the image against its containing area in the straightforward case. Neither rule proves that every child component or table will fit, and neither changes the meaning of box-sizing.
Inspect the overflowing content itself. If the card's border boundary is within the parent but a child extends beyond it, the problem is different from the card's border box exceeding the parent. This visual distinction can save a great deal of trial-and-error editing.
For practice, use a short paragraph first, then add a long token. Measure the card boundary before and after. If the boundary stays the same while the content protrudes, the arithmetic is still correct. The learner should describe the new issue as content overflow and choose an appropriate content-handling policy rather than shrinking unrelated padding until the symptom becomes less noticeable.
CHAPTER 18 OF 24 · Build and measure
18. Form controls and inline elements need inspection
Browser styles can give some form controls a border-box sizing policy while ordinary elements use another baseline unless author styles establish consistency. A student comparing a text input, button and div should inspect their computed values rather than assume identical user-agent styling.
Other properties also affect controls: default padding, borders, font metrics and platform appearance. A form layout can therefore look inconsistent even when the author has written the same width declaration. Establishing a scoped sizing policy is one helpful step, but the remaining styles still need review.
For ordinary non-replaced inline elements, width and height do not behave like the definite dimensions of a block card. A span with a width declaration may not create the rectangle the student expects. Changing box-sizing will not turn an ordinary inline element into an inline-block or block formatting box.
If a badge needs a controlled rectangular width, choose a suitable display mode and then apply the box model. The display decision determines whether the sizing declaration participates in the intended way. This is another example of why a correct property value can be insufficient for the surrounding design.
A useful comparison lab contains a block div, an inline span, an inline-block span and a form control. Give them clearly stated dimensions and inspect which ones use those dimensions as expected. Keep the content short and record the computed display and sizing policy for each. The student should learn to identify the kind of box being sized before applying the earlier arithmetic. That skill is more dependable than assuming all HTML tags respond identically to width and padding.
CHAPTER 19 OF 24 · Build and measure
19. Build a complete standalone measurement page
The following small page compares the two policies with identical dimensions. Save it as a disposable HTML file and open it in a browser. It is a standalone exercise, so the rules belong to this page rather than being pasted globally into an existing website.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Box sizing comparison</title>
<style>
body { font: 18px/1.6 system-ui; margin: 24px; }
.sample { width: 300px; padding: 20px; border: 2px solid #315c49; margin-bottom: 24px; }
.content-policy { box-sizing: content-box; }
.border-policy { box-sizing: border-box; }
</style>
</head>
<body>
<h1>Two sizing policies</h1>
<div class="sample content-policy">Content-box example</div>
<div class="sample border-policy">Border-box example</div>
</body>
</html>
Predict the two border-box widths before inspecting the page. The first should be three hundred and forty-four pixels, and the second should be three hundred, under the page's straightforward layout conditions. Both receive twenty pixels of padding on each side and two-pixel borders.
The page deliberately keeps other layout mechanisms out of the comparison. There are no flex items, grid tracks or percentage widths to negotiate. This controlled design makes the difference attributable to box-sizing rather than several simultaneous changes.
A narrow viewport may be too small for the fixed-width content-box example plus body margins. That is expected from the chosen dimensions and provides a later responsive-design discussion. Do not interpret it as evidence that the arithmetic changed. First understand the fixed measurement; then build a different rule for a page that should adapt to the viewport.
After the first comparison, change only padding to thirty pixels. Recalculate both widths and the second card's content width. This one-variable experiment is an efficient way to test whether the learner understands the relationship rather than simply recognising which box looks wider.
Developer tools can display the box model and computed styles of the selected element. Use those tools to compare a prediction with the actual layout. Select the exact sample box, inspect box-sizing, width, padding and border values, then identify the content and border-box measurements.
In a standalone measurement exercise, JavaScript can also read a rectangle. The example below obtains the rendered bounding rectangle widths of the two sample elements. Run it in the browser console for the page from the previous chapter.
for (const selector of [".content-policy", ".border-policy"]) {
const element = document.querySelector(selector);
console.log(selector, element.getBoundingClientRect().width);
}
Without transforms in this simple page, the reported widths correspond to the expected border-box rectangles: three hundred and forty-four and three hundred CSS pixels. A transform can alter the rendered bounding rectangle, so do not treat this measurement as a universal replacement for inspecting layout sizing. Fractional results can also occur in percentage and negotiated layouts.
CSS pixels are a layout unit, not a promise that one CSS pixel always equals one physical display pixel. Device pixel ratios and browser zoom affect the display relationship. For this lesson, compare measurements in CSS pixels so the declared dimensions and inspection results use a consistent unit.
When a prediction differs, record the actual values before changing the page. Check the active policy, all four relevant side values, display mode and parent layout. A mismatch is evidence that a condition in the model differs from the actual page. It is more useful to identify that condition than to keep editing numbers until the measurement happens to match the expected answer.
A fixed three-hundred-pixel comparison teaches arithmetic, but a useful reading card should often adapt to available space. A responsive version can use a percentage width with a maximum width and choose enough padding for the text while allowing the card's height to grow naturally.
.responsive-card {
box-sizing: border-box;
width: 100%;
max-width: 640px;
padding: clamp(16px, 4vw, 28px);
border: 1px solid #cfcabe;
overflow-wrap: anywhere;
}
This is a starting rule, not a complete guarantee of a good page. It needs a sensible parent, readable typography and realistic content. The viewport-based padding expression changes within its minimum and maximum bounds. The resulting content width must still be sufficient for the intended text and controls.
Check the page with a narrow viewport, larger text and a long label. A design that fits two short words may fail when the actual content is inserted. Border-box helps manage the card boundary, but accessibility and readability require attention to the content area as well.
If several cards form a layout, let the parent reflow appropriately. A two-column grid may become one column. Avoid treating smaller font sizes as the automatic solution to every narrow-screen problem. The student should consider whether the layout can change before making the reading experience less comfortable.
For a learning exercise, compare the fixed measurement page with the responsive rule and explain why the expected width is now conditional on the container. The learner should not keep demanding a three-hundred-pixel result after changing the design to a percentage. The specification changed, so the prediction must change with it.
When a card exceeds its parent, first compare the border boundaries. Is the card's own border box too wide, or is only a child or long token overflowing? That distinction determines whether to inspect the sizing budget or the content-handling rules first.
Next, inspect the active box-sizing value and the relevant width constraints. If the card uses content-box with a definite full width, added padding and borders may explain the excess. If it uses border-box, inspect margins, gaps, minimum sizes and the parent layout. The property should not be blamed for a rule outside its job.
If two cards wrap, calculate their total initial budget, including the gap and margins. In flex layout, inspect shrink and basis. In grid layout, inspect tracks and intrinsic minimums. If the border box fits but text is clipped vertically, inspect fixed height and content requirements rather than changing horizontal sizing.
If the computed policy differs from the intended policy, inspect the cascade, selector matching and stylesheet loading. A calculation based on a rule that never applies cannot predict the rendered result. This is why developer tools are a reasoning aid, not merely a place to tweak values until a screenshot looks tidy.
Keep a short correction note with the actual cause. Examples include “margin remained outside the full-width border box” or “the long token overflowed inside a correctly sized card”. Such notes are specific enough to transfer to a new project. A note saying “CSS was strange” provides no usable explanation.
The student should finish debugging with a sentence linking the change to its purpose. “I changed the parent to two fractional tracks so the gap is included in the allocation” is stronger evidence of understanding than “I changed fifty percent to forty-eight percent and it worked on my screen.”
CHAPTER 23 OF 24 · Diagnose and practise
23. Practise the arithmetic and support the learner
Try these questions without the examples open. A content-box card has width two hundred and sixty pixels, twelve-pixel padding on each horizontal side and one-pixel borders. Its border-box width is two hundred and eighty-six. Change only the policy to border-box, and its content width becomes two hundred and thirty-four. Explain both calculations in words.
Next, a border-box card has width one hundred percent in a four-hundred-pixel parent and ten-pixel horizontal margins. Do the margins fit inside the declared width? No. They remain outside the border box. A separate budget decision is needed. Then explain why adding a long unbroken token can create overflow without changing the card's border boundary.
For a transfer question, two fifty-percent cards have a sixteen-pixel gap. Does border-box alone guarantee that the layout fits? No. Padding and borders are accounted for within each card's sizing box, but the gap still belongs to the parent layout budget. The final result depends on the layout's rules and constraints.
In a Punggol family session, begin with one rectangle and one calculation. Ask the student to identify the measured box, add the relevant sides and predict the result before opening developer tools. A parent does not need to learn every CSS rule to support this explanation. The useful questions are concrete: “Where is the boundary?” and “Which space is outside it?”
If a tutor's help is needed, bring the smallest page that reproduces the symptom, along with the expected measurement and computed values. This is more informative than a screenshot alone. Use How Studying Works to connect explanation, fresh practice and correction. End with a changed example the student can calculate independently, so the session leaves evidence of a transferable skill.
CHAPTER 24 OF 24 · Diagnose and practise
24. Read the standards and choose the next task
The MDN box-sizing reference explains the property and offers comparisons. The CSS Sizing Level 3 specification defines its sizing behaviour and the non-negative content-box condition. The CSS box model specification provides the surrounding vocabulary for content, padding, borders and margins.
For layout questions, consult the Flexbox specification or the Grid specification when that mechanism is actually involved. Those sources describe additional allocation rules; they are not alternate definitions of box-sizing. Bring a precise question to the documentation, such as which minimum is preventing a flex item from shrinking.
A learner is ready to move on when they can calculate content and border-box dimensions under stated simple conditions, account for both sides, and explain that margins remain outside. They should also recognise when a percentage needs a containing-block basis and when another layout constraint makes the declared width insufficient to predict the final result.
The next useful task depends on the difficulty. If arithmetic is uncertain, draw another labelled rectangle. If the active rule is uncertain, practise computed-style inspection and the cascade. If geometry is secure, build a responsive two-card layout and test long content, gaps and a narrow viewport.
CSS becomes less mysterious when each property has a clear responsibility. Box-sizing decides how sizing values relate to the content and border boxes. The rest of the layout still needs an explicit budget and suitable content behaviour. A student who can separate those jobs can explain a page, repair it thoughtfully and apply the same reasoning to the next unfamiliar component.

