Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk2 min

How to Make a Sidebar Scroll with the Page and Stop at the Footer

A sticky sidebar stops at the footer when its wrapper ends with the page’s main content. Here’s the CSS pattern and what to check if it fails.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use position: sticky on the sidebar and place it inside a wrapper that ends before the footer. The sidebar will stick after it reaches its top threshold, then stop at the wrapper’s bottom edge instead of overlapping the footer.

Keep the sidebar inside the content region

A sticky element is constrained by its containing block. Make the sidebar’s wrapper part of the page’s main content, and place the footer after that content:

<main class="layout">
  <article class="content">...</article>
  <aside class="sidebar-shell">
    <div class="sidebar">Sidebar content</div>
  </aside>
</main>
<footer>Footer</footer>
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 18rem;
  gap: 2rem;
  align-items: start;
}

.sidebar-shell {
  align-self: start;
}

.sidebar {
  position: sticky;
  top: 1rem;
}

Here, the grid makes a content column and an 18rem sidebar column. The sticky sidebar sits 1rem from the top of its scrolling container once it reaches that threshold. As you continue down the page, it cannot move beyond the bottom of its wrapper. Because the wrapper ends with the main content, the sidebar stops before the footer. This containment approach is also described in the Stack Overflow discussion and SitePoint’s explanation of sticky positioning.

Check why sticky positioning may not work

  • Give it an inset. Set a usable threshold such as top: 1rem. Without an inset, there is no point at which the element should stick.
  • Inspect ancestor overflow. Check the sidebar’s ancestors for overflow: hidden, overflow: auto, or overflow: scroll. These can establish a different scrolling container, changing where sticky positioning applies.
  • Keep the wrapper in the content region. The wrapper must end before the footer for its lower boundary to stop the sidebar at the right place.
  • Allow room to travel. If the wrapper is no taller than the sidebar, there is little or no distance over which sticky behavior can be seen.
  • Consider footer positioning. A separately fixed footer can overlay content. Reserve space for it, or avoid fixing it unless that overlap is intentional.

When JavaScript is a fallback

Older approaches use a scroll handler to compare the window’s scroll position with the footer’s top offset, account for the sidebar’s height and optional padding, then add or remove a fixed-position class as the footer approaches. This requires measuring and updating positions as the page scrolls. Switching an element to position: fixed can also make nearby content jump unless the layout preserves the space it occupied. The Stack Overflow answer discusses this approach and its layout concern: stop a fixed-position div at the footer.

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

As an Amazon Associate I earn from qualifying purchases.

For layouts that can provide a wrapper ending before the footer, CSS sticky is the simpler default: it does not depend on a scroll script, remains in document flow, and naturally respects the wrapper boundary. JavaScript is more relevant for older or unusual environments where that CSS layout cannot meet the requirement.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Sources and scope

SitePoint’s article on sticky positioning was published August 14, 2014, and updated November 7, 2024. The cited Stack Overflow answer was posted February 26, 2016. These sources explain the positioning pattern; they do not establish a browser-support matrix for every legacy environment.

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.

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

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.