liveBook · Manning

Proportion

As explained in Math for Web Design

A proportion is a mathematical relationship expressing the relative sizes of quantities or parts.

A proportion compares a part with a whole or another quantity. In frontend work, percentages express that relationship: a 50% child inside a 1000px parent becomes 500px wide. The useful question is always: percentage of what? section 6.3.1

CSS answers that question differently by property. Width, horizontal offsets, and horizontal padding or margins use a parent or containing-block width. Percentage heights need an explicit parent height. Line-height percentages use the element’s own font size. The surprising rule is that vertical margins and padding also resolve from the parent’s width, not its height. section 3.4.3 section 6.3.1

Trace nested proportions

Percentages multiply as they nest. With an 800px root, a parent at 50% is 400px; its child at 50% is 200px. In general: child width = root width × each percentage expressed as a decimal. Trace this chain before changing values when a nested layout appears unexpectedly small. section 3.1.3

Listing 3.3 The multiplicative progression of percentages
CSS:
.grandparent {
    width: 800px;
}
.parent {
    width: 50%;    #1
}
.child {
    width: 50%;    #2
}

HTML:
<main class="grandparent">
    <h1>Main (.grandparent)</h1>
    <article class="parent">
        <h2>Article (.parent)</h2>
            <section class="child">
                <h3>Section (.child)</h3>
            </section>
    </article>
</main>

Inspect the nested 50% containers to verify how each percentage takes its immediate parent as its reference. section 3.1.3

Proportions turn a fixed layout into a liquid one. First choose a readable maximum width for the outer container. Then convert each fixed child width with: element percentage = (element fixed width ÷ parent fixed width) × 100. A 640px article in a 960px container becomes 66.67%, so it scales as the container changes. section 6.3.4

Use proportional values deliberately:

  • Set an image to width: 100% and height: auto so it fits its container without distortion. section 6.1.1
  • Keep percentage padding and margins in the box-model calculation; content-box adds them outside the declared width, while border-box includes them. section 3.5.4
  • Choose viewport units rather than percentages when the target is a share of the browser viewport instead of a share of the parent. section 6.4
  • Convert a scroll ratio from 0 to 1 into a displayed percentage for a progress indicator’s width, label, and color. section 13.3.1

Proportion is not limited to layout. A scroll position divided by scrollable height produces a progress ratio; multiplying it by 100 yields a percentage for UI feedback. The same normalized value can drive a bar width and a color change, keeping several visual effects synchronized. section 13.3.1

How Math for Web Design covers it

How deep it goes
Explains property-specific reference values, nested multiplication, box-model effects, liquid-layout conversion, and scroll-progress calculations.
Examples
Uses nested 50% containers, a responsive hero image, a fixed-to-liquid article layout, and a reading-progress indicator.
What you can do after
Apply it via CSS and JavaScript to calculate responsive dimensions, convert fixed layouts, and drive scroll-based progress displays.
How it connects
Connects percentages with responsive design, viewport units, box sizing, CSS inheritance, calc(), and JavaScript scroll position.

Also explained in

Compare how 4 books explain proportion →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Math for Web Design. The section links point to the parts of the book it draws on.