Karya Semi
HomeBlogSearchCategoriesAboutContact
Karya Semi

Less noise. More notes.

HomeBlogAboutContactPrivacy PolicyDisclaimer

© 2026 Karya Semi. All rights reserved.

XGitHubLinkedIn
  1. Home
  2. /Categories
  3. /Web Development

We Finally Learned to Center a Div, Then Browsers Added Sidebars

Browser sidebars in Chrome and Safari are eating into viewport width and breaking layouts that developers spent years getting right. What changed, what breaks, and how to handle it.

Dian Rijal Asyrof/August 5, 2026/6 min read
Illustration for We Finally Learned to Center a Div, Then Browsers Added Sidebars

We spent years learning to center a div. Flexbox, Grid, the holy grail of margin: 0 auto - we finally got there. And then browsers said "cool, here's a sidebar that eats 400 pixels of your viewport width."

Chrome shipped its Side Panel. Safari brought back its sidebar. Firefox has had sidebars for ages. And every single one of them changes the available viewport width in ways that break layouts developers already shipped to production.

This isn't a theoretical problem. It's happening right now, on real websites, to real users. And most developers have no idea.

What Are Browser Sidebars, Exactly?

Not the sidebar on your website. The sidebar that is the browser.

Chrome's Side Panel lets users open bookmarks, reading lists, search results, or Gemini alongside the current page. Safari's sidebar shows bookmarks, reading list, and tab groups. Firefox has had a bookmarks sidebar for years, plus extensions like Tree Style Tab that make sidebars central to the browsing experience.

The key detail: when these sidebars open, they don't overlay your content. They push it. The browser's rendering viewport shrinks.

Open Chrome's Side Panel and watch the page reflow. If you've built anything with vw units, fixed widths, or assumptions about available horizontal space - congratulations, your layout just shifted.

What Actually Breaks

The damage falls into a few categories, and some of them are subtle enough that you won't catch them in standard testing.

vw units become wrong. The 100vw value still reflects the full browser window width, not the reduced viewport. So a width: 100vw element extends behind the sidebar. You get a horizontal scrollbar. The classic 100vw overflow bug that haunted developers for years now has a new trigger.

This one stings because vw was supposed to be the safe, modern way to handle full-width layouts. It was the fix for width: 100% weirdness. And now it's broken again - just in a different way.

Media queries respond to the wrong width. Or rather, the right width - the full window width. Your @media (max-width: 768px) breakpoint fires at 768 pixels of total browser width, not the visible content area. A user with a 1200px screen and a 400px sidebar has 800px of visible content. But your breakpoint at 768px thinks they still have 1200px.

That responsive layout you built? It's showing the desktop version in 800 pixels of space. Text is cramped. Grid columns are squeezed. Navigation overflows.

Fixed-position elements assume full width. Headers, footers, and floating action buttons built with position: fixed; width: 100% might not reflow when the sidebar opens. They sit at full browser width and either get clipped by the sidebar or create overflow.

Horizontal scroll containers break. Anything using overflow-x: auto with calculated widths gets thrown off. The available space changes but the container doesn't know.

Centered max-width containers look off. The classic max-width: 1200px; margin: 0 auto pattern still works mechanically, but the visual centering shifts. The container centers relative to the full viewport, not the visible area. With a sidebar open, content looks shoved to one side.

Why This Is Different From Resizing a Window

The natural response is "just build responsive layouts." But sidebar-induced viewport changes behave differently from a user dragging a window edge.

First, the change is instant. No resize event fires in some implementations. Your JavaScript that listens for resize events to recalculate layouts might not trigger.

Second, the full window dimensions don't change. window.innerWidth might still report the pre-sidebar value. So even your JavaScript measurements are wrong.

Third, users don't think of it as "making the viewport smaller." They're adding a tool to their browsing experience. They don't expect the website to break. When they report the bug, they'll say "your site looks weird" - not "I opened Chrome's side panel."

And fourth, there's no standard for how different browsers handle this. Chrome does it one way, Safari another. Firefox with extension-driven sidebars has its own behavior. You're not dealing with a single specification - you're dealing with browser vendors independently deciding to carve space out of your viewport.

The CSS That Actually Works

Here's where we land in practical territory. There are a few approaches, and the right one depends on your layout.

Stop using vw for full-width layouts. Seriously. Use width: 100% on block elements instead. The vw unit measures the viewport, not the available space. For most full-width sections, width: 100% on a block element already works and respects the containing block's width. The only time you need vw is when you intentionally want to break out of a container - a full-bleed image, a background that spans edge to edge.

If you must use vw for full-bleed effects, calculate it:

.full-bleed {
  width: 100vw;
  margin-left: calc(50% - 50vw);
}

That 50% - 50vw trick accounts for the offset between the container and the viewport edge. But even this breaks when the viewport shrinks from a sidebar, because 50vw is still the full viewport width.

A safer approach uses container-relative math:

.full-bleed {
  width: 100%;
  position: relative;
  left: 50%;
  right: 50%;
  margin-left: -50vw;
  margin-right: -50vw;
  max-width: 100vw;
}

But honestly? The cleanest fix in modern CSS is using the 100dvw (dynamic viewport width) unit where supported, though browser support for how sidebars affect dvw is still inconsistent.

Use @media queries carefully, or use container queries. Media queries respond to viewport width, which may or may not reflect the visible area. Container queries respond to the parent element's width, which does reflect the available space.

.card-grid {
  container-type: inline-size;
  container-name: card-grid;
}
 
@container card-grid (min-width: 400px) {
  .card {
    flex: 0 0 calc(50% - 1rem);
  }
}

Container queries are the right tool here. They respond to the space actually available to the component, not the browser window. If a sidebar eats 400px, the container gets narrower, and your layout adapts. This is what they were built for - contextual responsive design.

Test for scrollbar-causing overflow. Add this as a quick diagnostic:

html {
  overflow-x: hidden;
}

Don't ship this as a fix - it masks the problem. But it helps you identify whether vw overflow is happening. If the horizontal scrollbar disappears with this rule, your vw usage is the culprit.

Rethink position: fixed assumptions. For fixed headers, consider using position: sticky instead. Sticky elements stay within the normal flow and respond to changes in available width. Fixed elements don't.

.header {
  position: sticky;
  top: 0;
  width: 100%;
  z-index: 100;
}

If you need fixed positioning for specific interactions (like a modal overlay), be explicit about width:

.modal-backdrop {
  position: fixed;
  inset: 0;
  /* Use inset instead of top/left/width/height */
  /* inset respects the layout viewport in most cases */
}

The Harder Problem: Detecting the Sidebar

There's no reliable API to detect whether a browser sidebar is open. Chrome doesn't fire a resize event. There's no sidebarOpen media feature in CSS (not yet, anyway).

You can approximate detection:

function checkViewportMismatch() {
  const viewportWidth = document.documentElement.clientWidth;
  const windowWidth = window.innerWidth;
  const sidebarWidth = windowWidth - viewportWidth;
  
  if (sidebarWidth > 50) {
    document.documentElement.classList.add('sidebar-active');
  } else {
    document.documentElement.classList.remove('sidebar-active');
  }
}

Run this on an interval or hook it into a MutationObserver on the document. It's hacky. It works sometimes. The clientWidth vs innerWidth delta gives you a rough sidebar width.

But this shouldn't be your primary defense. Build layouts that work at any width, and the sidebar becomes just another width change - one you don't need to specifically detect.

What We Should Be Building Instead

The sidebar situation exposes a deeper habit: we design for specific widths and call it responsive. We pick breakpoints at 640, 768, 1024, and 1280. We test at iPhone and common desktop sizes. And then we ship layouts that assume those are the only widths that matter.

Real viewport widths in 2026 include: a phone in split-screen mode. A laptop with a browser sidebar open. A desktop with two windows snapped side by side. A tablet with a picture-in-picture video floating over the browser. A foldable phone in its half-open state.

The fix isn't to handle each of these as a special case. It's to build layouts that genuinely don't care about the viewport width. Fluid typography with clamp(). Grid layouts with auto-fit and minmax(). Components that reflow from one column to four without hard breakpoints.

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));
  gap: 1.5rem;
}

That single line handles 300px and 3000px viewports, with or without sidebars, on any device. No media queries. No breakpoints. No assumptions about screen sizes.

The Bigger Picture

Browser sidebars aren't going away. If anything, browsers will add more UI that competes for viewport space. Chrome's experimenting with AI panels. Safari keeps adding features to its sidebar. And browser extensions have been building sidebar interfaces for years.

This is the new normal. The viewport isn't yours to assume anymore - it never really was, but we got away with it for a while.

The developers who'll handle this well are the ones who already build fluid, intrinsic layouts. The ones who treat specific pixel widths as guidelines, not contracts. The ones who've internalized that "responsive" means "works at every width" - not "has three breakpoints."

And for everyone else? At least now you know why that one client keeps saying the site "looks weird" on their machine. They probably have a sidebar open.

Check your vw usage. Lean on container queries. Test with a sidebar open. It's not glamorous work, but it's the kind of maintenance that keeps layouts from falling apart when browsers change the rules - again.

DR

Dian Rijal Asyrof

Writes about useful AI tools, programming practice, and the craft of building reliable software.

Previous articleDeepSeek V4 Flash Crashes the Single-GPU Barrier on AMD MI300XNext article8 Myths About Software Engineering and GenAI That Won't Die
CSSBrowser SidebarsViewportResponsive DesignWeb Compat
On this page↓
  1. What Are Browser Sidebars, Exactly?
  2. What Actually Breaks
  3. Why This Is Different From Resizing a Window
  4. The CSS That Actually Works
  5. The Harder Problem: Detecting the Sidebar
  6. What We Should Be Building Instead
  7. The Bigger Picture

On this page

  1. What Are Browser Sidebars, Exactly?
  2. What Actually Breaks
  3. Why This Is Different From Resizing a Window
  4. The CSS That Actually Works
  5. The Harder Problem: Detecting the Sidebar
  6. What We Should Be Building Instead
  7. The Bigger Picture

See also

Illustration for Jelly UI: Bringing Soft-Body Physics to Native HTML Form Controls Without JS Bloat
Web Development/Jul 21, 2026

Jelly UI: Bringing Soft-Body Physics to Native HTML Form Controls Without JS Bloat

How Jelly UI uses WebGL shaders, Spring physics, and DOM overlay mechanics to create expressive UI interactions while preserving HTML form accessibility.

3 min read
WebdevJavaScript
Illustration for CSS Baseline 2026: The Browser Features Frontend Developers Can Start Using
Web Development/Jun 28, 2026

CSS Baseline 2026: The Browser Features Frontend Developers Can Start Using

Baseline 2026 is turning several browser features into practical defaults. Here is what frontend developers should test before adding more JavaScript.

2 min read
CSSFrontend