Sidebar layout

A sidebar layout sets an <aside> beside the content: a menu, filters or notes next to the thing being read. It is one class on a wrapper. The aside keeps its own width, the content takes the rest, and when the screen is too narrow for both, the aside drops beneath it without a media query.

On the left

Put the aside first and it sits on the left. Everything that is not the aside is the content, and takes the remaining width.

<div class="sidebar">
  <aside aria-label="Account menu">
    <menu>
      <ul>
        <li><p>Account</p></li>
        <li><a href="profile/" aria-current="page">Profile</a></li>
        <li><a href="security/">Security</a></li>
        <li><a href="billing/">Billing</a></li>
      </ul>
    </menu>
  </aside>
  <div class="card">
    <h3>Profile</h3>
    <p>Your name and photo.</p>
  </div>
</div>
A menu in an aside on the left

Width

The aside asks for 12rem. Set --side on the wrapper for another width; it is a one-off, so it goes inline.

<div class="sidebar" style="--side: 7rem">
  <aside class="panel" aria-label="Filters">Filters</aside>
  <div class="panel">The content takes the rest.</div>
</div>
A narrow aside, set with "--side"

Narrow screens

The content asks for at least half the row. When the aside's width and that half no longer fit, the aside wraps onto its own line and both take the full width. There is no breakpoint to choose: it follows the space the layout actually has, so it works the same in a narrow column as on a narrow screen. Drag the corner of the box to make it narrower and watch the aside drop beneath.

<div class="resizable" role="region" aria-label="Resizable example" tabindex="0">
  <div class="sidebar">
    <aside class="panel" aria-label="Example aside">Aside</aside>
    <div class="panel">Content</div>
  </div>
</div>
A sidebar inside a box you can resize
.sidebar { display: flex; flex-wrap: wrap; gap: var(--gap); }
.sidebar > aside { flex: 1 1 var(--side, 12rem); }
.sidebar > :not(aside) { flex: 999 1 0; min-width: 50%; }
The whole rule: the content grows first and never drops below half

Keeping the aside in view

For a long article, make the aside sticky so it stays in view while the content scrolls past. Here the article scrolls inside a box, so the aside sticks to the top of the box: scroll it to see. On a page, use top: calc(var(--pinned) + 16px) instead, so the aside comes to rest just below the site header.

<div role="region" aria-label="Long article" tabindex="0" style="max-height: 220px">
  <div class="sidebar">
    <aside class="panel" aria-label="Contents" style="position: sticky; top: 0">Contents</aside>
    <div class="column">
      <p>The first part of a long article.</p>
      …
    </div>
  </div>
</div>
A sticky aside beside an article that scrolls

Accessibility

aside
A complementary landmark, so a screen reader can jump to it or past it.
aria-label
Names the aside. Give each aside a different name when a page has more than one.
Source order
The order in the markup is the reading order and the stacking order, so put first whatever should be read first.