How to Make a Child Div Have 100% Height of Its Parent

Master CSS layout techniques including flexbox, CSS Grid, and absolute positioning to solve the common height percentage problem.

The Frustrating Mystery of Percentage Heights

Every web developer has faced this scenario: you apply height: 100% to a child element, expecting it to fill its parent's height, but nothing happens. The element remains stubbornly sized to its content. This isn't a bug--it's a fundamental aspect of how CSS calculates heights that often surprises developers.

In this guide, we'll unravel the mystery behind percentage-based heights, explore modern solutions, and help you choose the right approach for your specific use case. For a deeper dive into modern layout techniques, check out our guide on flexbox layout patterns.

The Circular Calculation Problem

Why height: 100% Doesn't Work as Expected

Understanding why height: 100% fails requires grasping how CSS fundamentally differs between width and height calculations. According to CSS specifications, these two properties work in opposite ways.

When calculating an element's width, the browser looks upward to the parent element. Block-level elements naturally expand to fill available horizontal space, so width: 50% simply means "take half of whatever width my parent provides." This is straightforward and predictable.

However, height works completely differently. By default, block-level elements use height: auto, meaning their height is determined by their content. The browser looks downward through child elements to calculate vertical space needed, creating a circular calculation when we try to use percentage heights.

  • The child says: "I want to be 100% of my parent's height"
  • The parent says: "My height is determined by my children"
  • Result: Neither value can be resolved, so browsers typically ignore the percentage declaration

As explained by GeeksforGeeks' comprehensive guide on percentage heights, this circular dependency means that for a percentage height to work, the parent's height must be explicitly set--it cannot depend on content.

The Asymmetry Between Width and Height

The asymmetry between width and height behavior often catches developers off guard. While width: 100% reliably fills the parent's width, height: 100% requires explicit preparation of the parent chain.

This behavior stems from how document flow works in CSS. Block elements inherently fill available width but shrink-wrap their height based on content. Modern CSS provides elegant solutions that eliminate this complexity entirely.

Josh W. Comeau's in-depth analysis explains that this design choice made sense for document-style layouts but creates challenges for modern application-style interfaces.

Flexbox: The Elegant Solution

Setting Up Flexbox for Full-Height Layouts

Flexbox revolutionized how we approach height challenges. By converting a parent to a flex container, we unlock powerful alignment and sizing capabilities.

.parent {
 display: flex;
}

.child {
 height: 100%;
 /* Or: flex-grow: 1; */
}

The display: flex declaration transforms the parent into a flex formatting context. Children can specify their height as a percentage because flex containers establish a definite height reference for their items.

Flexbox Best Practices

  • Use align-items: stretch (default) to make children fill container height
  • Use flex-grow: 1 for more dynamic content handling
  • Combine with dvh units for viewport-aware layouts

According to GeeksforGeeks' guide, flexbox provides the cleanest solution for most full-height layout scenarios. For more examples of moving containers with flexbox, see our dedicated guide on moving containers with flexbox.

Why Flexbox Works

The key insight is that flex items (children of a flex container) can use flex-grow or height: 100% without any special preparation of the parent. The flex formatting context changes how heights are calculated entirely. Even using flex-grow: 1 on the child tells it to consume all available space in the main axis, which handles dynamic content more gracefully.

When building responsive layouts with Next.js or other modern frameworks, flexbox should be your go-to solution for full-height components. Always consider the alignment axis--use justify-content for the main axis and align-items for the cross axis.

Flexbox Solution
1.parent {2 display: flex;3}4 5.child {6 height: 100%;7 /* Alternative: */8 flex-grow: 1;9}
CSS Grid Solution
1.parent {2 display: grid;3}4 5.child {6 height: 100%;7}8 9/* Or with explicit rows: */10.parent {11 display: grid;12 grid-template-rows: 1fr 1fr 1fr;13}

CSS Grid: Powerful Two-Dimensional Layouts

Grid-Based Full-Height Solutions

CSS Grid offers another powerful approach, particularly valuable for complex layouts. The simplest grid approach:

.parent {
 display: grid;
}

Like flexbox, Grid establishes a definite height context for its children. The difference is Grid handles two dimensions simultaneously, while flexbox excels at one-dimensional layouts.

When to Choose Grid

Grid should be your choice when you need true two-dimensional layout control--specifying both row and column sizes simultaneously. Complex page layouts with distinct header, sidebar, main content, and footer areas often work better with Grid.

Grid also excels when you need consistent alignment across multiple rows or columns. While flexbox can align items, it does so within each flex line independently. Grid's align-items and justify-items properties work consistently across the entire grid.

The fr unit (fraction) distributes available space proportionally, making it excellent for dividing layouts into equal-height sections. Combined with grid-template-areas, you can create complex full-height layouts that would require nested flexbox containers otherwise.

For simple full-height containers with a single child, flexbox typically requires less code and is more performant. Reserve Grid for when you genuinely need its two-dimensional capabilities, as documented in GeeksforGeeks' comprehensive comparison.

Absolute Positioning: The Traditional Approach

Understanding the Position Context

Before flexbox and Grid became widely supported, absolute positioning was the primary technique. While modern layouts rarely need this approach, understanding it helps you recognize when it might still be appropriate.

The absolute positioning method works by breaking the normal document flow:

.parent {
 position: relative;
}

.child {
 position: absolute;
 top: 0;
 bottom: 0;
}

Setting position: relative on the parent creates a containing block. The child's top: 0; bottom: 0 tells it to stretch from top to bottom edge, as explained in GeeksforGeeks' documentation.

Limitations

  • Child is removed from document flow
  • Parent collapses (height becomes zero)
  • Can cause overlapping and accessibility issues

When Absolute Positioning Still Makes Sense

Absolute positioning may still be appropriate for overlay patterns (modals, tooltips, dropdown menus), decorative elements that should not affect document flow, or legacy browser support scenarios where flexbox and Grid are unavailable. For general layout purposes, however, flexbox and Grid provide superior solutions with fewer trade-offs.

Modern Best Practices

Choose the right approach for your project

Use Flexbox by Default

Flexbox should be your go-to solution for most full-height layouts. It's widely supported, intuitive, and solves the problem with minimal code.

Choose Grid for Complex Layouts

Use CSS Grid when you need true two-dimensional control or complex page layouts with multiple regions.

Avoid Absolute Positioning

Reserve absolute positioning for overlays and tooltips. Avoid it for general layout construction.

Use box-sizing: border-box

Include `* { box-sizing: border-box; }` to simplify height calculations that account for padding and border.

css\n.card {\n display: flex;\n flex-direction: column;\n min-height: 100%;\n}\n\n.card-body {\n flex-grow: 1;\n}\n

Frequently Asked Questions

Conclusion

The "height: 100% doesn't work" problem has puzzled developers for years, but modern layout systems make it a non-issue:

  • Flexbox should be your default choice--well-supported, intuitive, and solves the circular calculation problem elegantly
  • CSS Grid provides additional capabilities for complex two-dimensional layouts
  • Absolute positioning remains useful for overlays, tooltips, and specific patterns

Understanding why percentage heights behave this way helps you make better decisions about which technique to use. By choosing the right tool for each situation and following established patterns, you can build robust, maintainable layouts that work consistently across browsers and devices.

The goal isn't to fight against CSS's height calculation rules, but to use layout systems designed to handle these challenges naturally. Whether you're building with Next.js, Vue, or vanilla CSS, these modern techniques will help you create layouts efficiently without fighting against percentage height calculations.

Ready to build modern, responsive layouts? Our web development services team can help you implement these techniques in your next project. For more CSS layout insights, explore our guide on width of divs and sizing patterns.

Need Help Building Modern Web Layouts?

Our team of experienced developers can help you implement responsive, performant layouts using the latest CSS techniques and frameworks.