Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

width: 100% fills the parent, not the browser window. To make a child inside a centered, constrained parent span the viewport, either restructure the markup so a full-width section wraps a constrained inner element, or use 100vw with an offset calculated for the parent’s known geometry. Choose container queries instead when the component should respond to its container’s size rather than escape it.

Why width: 100% stops at the parent

A percentage width is resolved against the element’s containing block. If that block is a centered content column, width: 100% fills that column. Viewport width units use the viewport as their reference, so width: 100vw can size an element to the browser viewport instead. MDN explains the distinction in its guide to CSS sizing.

Choose an approach for the layout you need

Approach Best fit Main consideration
Full-width outer section with constrained inner wrapper You can change the markup and want a full-bleed background or border with readable, constrained content. Requires putting the section outside the constrained wrapper.
100vw plus a calculated offset The child must stay in normal flow within existing constrained markup. Depends on the parent being centered and its width being known at the breakpoint.
Container queries A component’s styles should respond to its containing component’s size. They style based on the container; they do not make a child span the viewport.

When you can change the markup: use a full-width outer section

Make the section itself the full-width element, then place its content in a separate constrained wrapper. The section can carry the background or border across the viewport while the inner wrapper keeps text and other content aligned with the page’s readable content width. CSS-Tricks describes this structure for full-browser-width bars.

<section class="band">
  <div class="band__inner">
    <h2>Section heading</h2>
    <p>Content stays within the readable page width.</p>
  </div>
</section>
.band {
  width: 100%;
  background: #eee;
}

.band__inner {
  max-width: 40em;
  margin-inline: auto;
  padding: 1rem;
}

Here, the band is not trying to escape a constrained parent: it is outside that constraint. The inner wrapper provides the limit instead.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

When the child must remain in the constrained markup: use a viewport width and offset

If restructuring is not practical and the child must remain in normal flow, the documented CSS-Tricks example uses a viewport width and translates the element horizontally. The example assumes the centered parent is 40em wide at the specified breakpoint:

@media (min-width: 40em) {
  .full-width {
    width: 100vw;
    transform: translateX(calc((40em - 100vw) / 2));
  }
}

At viewports wider than 40em, the calculation shifts the viewport-width child left by half the difference between the parent width and viewport width. That aligns the child’s left edge with the viewport’s left edge when the parent is centered; its 100vw width then reaches the other edge. The example comes from Chris Coyier’s July 25, 2016 article.

This is geometry-specific CSS, not a universal escape rule. If the parent is not centered, has a different width, or changes width at another breakpoint, update the calculation to match. Coyier’s article also discusses an @supports wrapper; its historical account of inconsistent behavior is not a current cross-browser compatibility test.

When container queries are the right tool

Use container queries when a component’s layout should change according to the available size of its containing component. They are designed to style based on container features, rather than viewport size. That solves a different problem from making a child extend to the browser edges. See MDN’s guide to container size and style queries.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check for horizontal overflow

A 100vw element can contribute to horizontal overflow. Viewport measurements can vary with the browser’s viewport model and scrollbar behavior; MDN documents these details in its guide to viewport concepts. After applying either full-bleed technique, inspect the page at the target viewport sizes and check whether the page scrolls horizontally or content is clipped.

  • Check the actual layout, including the parent’s width and centering at each relevant breakpoint.
  • Inspect the rendered page and its scrollable width in the browsers you support.
  • Do not apply overflow-x: hidden as a blind fix. The CSS overflow property controls what happens when content overflows, and hiding overflow can conceal content that extends beyond the viewport.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.