10 CSS Sidebar Navigation 09 / 10

Responsive Off-Canvas Mobile Sidebar Navigation Overlay

A mobile slide-out sidebar with a CSS overlay for a food-delivery app (Fork&Go), mobile-first.

Best formobile-first apps, e-commerce, food delivery, anywhere the design starts at phone width and adapts up.

Pure CSS MIT licensed
Live Demo Open in tab
Open in playground

The code

<section class="sn-off" aria-label="Off-canvas mobile sidebar demo">
  <input type="checkbox" id="sn-off-m" class="toggle" aria-label="Toggle navigation">

  <aside class="drawer" aria-label="Account navigation">
    <div class="d-head">
      <label for="sn-off-m" class="close" aria-label="Close navigation"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" aria-hidden="true"><path d="M18 6L6 18M6 6l12 12" stroke-width="2"/></svg></label>
      <div class="ava" aria-hidden="true">🍜</div>
      <b>Hey, Marcus</b>
      <small>Deliver to · 14 Maple St</small>
    </div>
    <nav class="d-nav">
      <a class="item active" href="#"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" aria-hidden="true"><path d="M3 9l9-7 9 7v11a2 2 0 01-2 2H5a2 2 0 01-2-2z"/></svg>Browse</a>
      <a class="item" href="#"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" aria-hidden="true"><path d="M6 2l1.5 1.5M18 2l-1.5 1.5M3 8h18l-1 13a2 2 0 01-2 2H6a2 2 0 01-2-2z"/></svg>Restaurants</a>
      <a class="item" href="#"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" aria-hidden="true"><path d="M16 4h2a2 2 0 012 2v14l-6-3-6 3-6-3V6a2 2 0 012-2h2"/><path d="M9 2h6v4H9z"/></svg>My Orders<span class="badge">2</span></a>
      <a class="item" href="#"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" aria-hidden="true"><path d="M20.8 4.6a5.5 5.5 0 00-7.8 0L12 5.6l-1-1a5.5 5.5 0 00-7.8 7.8l1 1L12 21l7.8-7.6 1-1a5.5 5.5 0 000-7.8z"/></svg>Favorites</a>
      <a class="item" href="#"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" aria-hidden="true"><rect x="1" y="4" width="22" height="16" rx="3"/><path d="M1 10h22"/></svg>Payment</a>
      <a class="item" href="#"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" aria-hidden="true"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 00.33 1.82l.06.06a2 2 0 01-2.83 2.83l-.06-.06a1.65 1.65 0 00-2.82 1.17V21a2 2 0 01-4 0v-.09A1.65 1.65 0 007 19.4a1.65 1.65 0 00-1.82.33l-.06.06a2 2 0 11-2.83-2.83l.06-.06A1.65 1.65 0 004.6 14H4.5a2 2 0 010-4h.09A1.65 1.65 0 006 8.6"/></svg>Settings</a>
    </nav>
    <div class="d-foot">
      <div class="promo"><b>50% off first order 🎉</b><p>Use code FRESH50 at checkout</p></div>
    </div>
  </aside>
  <label for="sn-off-m" class="overlay" aria-hidden="true"></label>

  <div class="mainpane">
    <header class="appbar">
      <label for="sn-off-m" class="menu-btn" aria-label="Open navigation"><svg viewBox="0 0 24 24" fill="none" aria-hidden="true"><path d="M4 6h16M4 12h16M4 18h16" stroke-width="2" stroke-linecap="round"/></svg></label>
      <div class="title">Fork<span>&amp;</span>Go</div>
      <div class="cart" aria-label="Cart, 2 items"><svg viewBox="0 0 24 24" fill="none" aria-hidden="true"><circle cx="9" cy="21" r="1"/><circle cx="20" cy="21" r="1"/><path d="M1 1h4l2.7 13.4a2 2 0 002 1.6h9.7a2 2 0 002-1.6L23 6H6"/></svg><b>2</b></div>
    </header>
    <main class="contentpane">
      <div class="hint">☰ Tap the menu to slide out the navigation</div>
      <div class="food">
        <div class="img" aria-hidden="true"></div>
        <div class="body"><b>Ramen House</b><div class="row"><span class="star">★ 4.8</span>· 20–30 min<span class="price">$$</span></div></div>
      </div>
      <div class="food">
        <div class="img green" aria-hidden="true"></div>
        <div class="body"><b>Green Bowl</b><div class="row"><span class="star">★ 4.6</span>· 15–25 min<span class="price">$</span></div></div>
      </div>
    </main>
  </div>
</section>
/* ─── 09 Off-Canvas Mobile Sidebar — food delivery ────────── */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700;800&display=swap');

.sn-off {
  --sn-off-bg: #fff8f0;
  --sn-off-ink: #241a12;
  --sn-off-muted: #9b8a78;
  --sn-off-line: #f0e4d4;
  --sn-off-orange: #ff6b35;
  --sn-off-orange-d: #e9531c;
  --sn-off-cream: #fff;

  position: relative;
  width: 100%;
  height: 600px;
  font-family: 'DM Sans', sans-serif;
  background: var(--sn-off-bg);
  color: var(--sn-off-ink);
  overflow: hidden;
  box-sizing: border-box;
}
.sn-off *, .sn-off *::before, .sn-off *::after { box-sizing: border-box; margin: 0; padding: 0; }

.sn-off .toggle { display: none; }

.sn-off .appbar {
  position: sticky; top: 0; z-index: 15; display: flex; align-items: center; gap: 1rem;
  padding: 1rem 1.2rem; background: var(--sn-off-cream); border-bottom: 1px solid var(--sn-off-line);
}
.sn-off .menu-btn { cursor: pointer; width: 42px; height: 42px; border-radius: 13px; background: var(--sn-off-bg);
  display: grid; place-items: center; flex-shrink: 0; }
.sn-off .menu-btn svg { width: 22px; height: 22px; stroke: var(--sn-off-ink); }
.sn-off .appbar .title { font-weight: 800; font-size: 1.2rem; letter-spacing: -.02em; }
.sn-off .appbar .title span { color: var(--sn-off-orange); }
.sn-off .cart { margin-left: auto; width: 42px; height: 42px; border-radius: 13px; background: var(--sn-off-orange);
  display: grid; place-items: center; position: relative; flex-shrink: 0; }
.sn-off .cart svg { width: 21px; height: 21px; stroke: #fff; }
.sn-off .cart b { position: absolute; top: -5px; right: -5px; background: var(--sn-off-ink); color: #fff;
  font-size: .66rem; width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; }

.sn-off .drawer {
  position: absolute; top: 0; left: 0; bottom: 0; width: 300px; max-width: 84%;
  background: var(--sn-off-cream); z-index: 40;
  transform: translateX(-100%); transition: transform .38s cubic-bezier(.4,0,.2,1);
  display: flex; flex-direction: column; box-shadow: 14px 0 50px rgba(0,0,0,.18);
}
.sn-off .toggle:checked ~ .drawer { transform: translateX(0); }
.sn-off .overlay { position: absolute; inset: 0; background: rgba(36,26,18,.5); z-index: 30;
  opacity: 0; visibility: hidden; transition: .38s; }
.sn-off .toggle:checked ~ .overlay { opacity: 1; visibility: visible; }

.sn-off .d-head { padding: 1.6rem 1.5rem; background: linear-gradient(135deg, var(--sn-off-orange), var(--sn-off-orange-d)); color: #fff; position: relative; }
.sn-off .d-head .ava { width: 54px; height: 54px; border-radius: 16px; background: rgba(255,255,255,.25);
  display: grid; place-items: center; font-size: 1.6rem; margin-bottom: .8rem; }
.sn-off .d-head b { font-size: 1.2rem; font-weight: 700; }
.sn-off .d-head small { display: block; opacity: .85; font-size: .82rem; margin-top: .1rem; }
.sn-off .close { position: absolute; top: 1.3rem; right: 1.3rem; cursor: pointer; color: #fff;
  width: 32px; height: 32px; border-radius: 9px; background: rgba(255,255,255,.2); display: grid; place-items: center; }
.sn-off .close svg { width: 18px; height: 18px; }

.sn-off .d-nav { flex: 1; overflow-y: auto; padding: 1rem .9rem; }
.sn-off .item { display: flex; align-items: center; gap: 1rem; padding: .85rem 1rem; border-radius: 14px;
  color: var(--sn-off-ink); text-decoration: none; font-weight: 600; font-size: .96rem; transition: .16s; }
.sn-off .item svg { width: 22px; height: 22px; stroke: var(--sn-off-muted); stroke-width: 1.9; flex-shrink: 0; }
.sn-off .item:hover { background: var(--sn-off-bg); }
.sn-off .item.active { background: #fff1e8; color: var(--sn-off-orange-d); }
.sn-off .item.active svg { stroke: var(--sn-off-orange-d); }
.sn-off .item .badge { margin-left: auto; background: var(--sn-off-orange); color: #fff; font-size: .7rem;
  font-weight: 700; padding: .12rem .5rem; border-radius: 20px; }
.sn-off .d-foot { padding: 1.2rem 1.5rem; border-top: 1px solid var(--sn-off-line); }
.sn-off .promo { background: var(--sn-off-ink); color: #fff; border-radius: 16px; padding: 1.1rem 1.2rem; }
.sn-off .promo b { font-size: .95rem; }
.sn-off .promo p { font-size: .78rem; opacity: .7; margin-top: .2rem; }

.sn-off .mainpane { height: 100%; overflow-y: auto; display: flex; flex-direction: column; }
.sn-off .contentpane { padding: 1.3rem 1.2rem; max-width: 560px; margin: 0 auto; }
.sn-off .hint { background: #fff1e8; border: 1px dashed var(--sn-off-orange); border-radius: 14px;
  padding: .9rem 1.1rem; color: var(--sn-off-orange-d); font-size: .88rem; font-weight: 600; margin-bottom: 1.3rem; text-align: center; }
.sn-off .food { background: var(--sn-off-cream); border: 1px solid var(--sn-off-line); border-radius: 20px; overflow: hidden; margin-bottom: 1.2rem; }
.sn-off .food .img { height: 130px; background: linear-gradient(135deg, #ffd5a8, #ff6b35); }
.sn-off .food .img.green { background: linear-gradient(135deg, #c8e6a0, #5ac26a); }
.sn-off .food .body { padding: 1.1rem 1.3rem; }
.sn-off .food .body b { font-size: 1.1rem; }
.sn-off .food .body .row { display: flex; align-items: center; gap: .6rem; margin-top: .4rem; color: var(--sn-off-muted); font-size: .85rem; }
.sn-off .food .body .price { margin-left: auto; color: var(--sn-off-ink); font-weight: 800; font-size: 1.1rem; }
.sn-off .star { color: var(--sn-off-orange); }

@media (min-width: 920px) {
  .sn-off .drawer { position: static; transform: none; box-shadow: none; border-right: 1px solid var(--sn-off-line); flex-shrink: 0; }
  .sn-off .overlay, .sn-off .menu-btn, .sn-off .close { display: none; }
  .sn-off { display: flex; flex-direction: row; }
  .sn-off .mainpane { flex: 1; }
  .sn-off .appbar { display: none; }
  .sn-off .contentpane { margin: 0; padding: 2.5rem; max-width: 680px; }
  .sn-off .hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .sn-off .drawer, .sn-off .overlay { transition: none; }
}

Search CodeFronts

Loading…