UI Components Easy
Rectangular Navigation
Compact vertical icon sidebar for mobile apps. Always-visible narrow rail with icon buttons and active indicator.
Open in Lab
MCP
css vanilla-js
Targets: JS HTML
Code
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
:root {
--bg: #050910;
--nav-bg: #0d1117;
--surface: #161b22;
--accent: #38bdf8;
--text: #e2e8f0;
--text-muted: #94a3b8;
--sidebar-width: 52px;
}
body {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
background: var(--bg);
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
color: var(--text);
padding: 2rem;
}
/* ── Demo wrapper ── */
.demo {
width: 100%;
max-width: 400px;
display: flex;
flex-direction: column;
align-items: center;
gap: 2rem;
}
.demo-title {
font-size: 1.5rem;
font-weight: 800;
text-align: center;
}
.demo-sub {
color: var(--text-muted);
font-size: 0.875rem;
text-align: center;
}
/* ── Phone frame ── */
.phone-frame {
width: 320px;
border-radius: 32px;
border: 1.5px solid rgba(255, 255, 255, 0.08);
background: var(--nav-bg);
overflow: hidden;
box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.04);
}
.phone-screen {
position: relative;
width: 100%;
height: 520px;
display: flex;
flex-direction: column;
overflow: hidden;
}
/* ── Status bar ── */
.status-bar {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 20px 6px;
font-size: 12px;
font-weight: 600;
color: var(--text-muted);
flex-shrink: 0;
}
.status-icons {
font-size: 9px;
letter-spacing: 3px;
}
/* ── App layout: sidebar + content ── */
.app-layout {
display: flex;
flex: 1;
overflow: hidden;
}
/* ── Vertical icon sidebar ── */
.sidebar {
width: var(--sidebar-width);
flex-shrink: 0;
background: var(--nav-bg);
border-right: 1px solid rgba(255, 255, 255, 0.06);
display: flex;
flex-direction: column;
align-items: center;
padding: 12px 0;
gap: 4px;
}
/* ── Nav button ── */
.nav-btn {
display: flex;
align-items: center;
justify-content: center;
width: 40px;
height: 40px;
border: none;
background: transparent;
color: var(--text-muted);
border-radius: 10px;
cursor: pointer;
transition: background 0.25s, color 0.25s;
-webkit-tap-highlight-color: transparent;
}
.nav-btn:hover {
background: rgba(255, 255, 255, 0.06);
color: var(--text);
}
.nav-btn:focus-visible {
outline: 2px solid var(--accent);
outline-offset: -2px;
}
.nav-btn.active {
background: rgba(56, 189, 248, 0.15);
color: var(--accent);
}
/* ── Content area ── */
.content-area {
flex: 1;
overflow-y: auto;
background: var(--bg);
padding: 20px 16px;
}
.content-page {
display: none;
}
.content-page.active {
display: block;
}
.content-page h2 {
font-size: 1.125rem;
font-weight: 700;
margin-bottom: 6px;
}
.content-page p {
font-size: 0.8rem;
color: var(--text-muted);
line-height: 1.5;
margin-bottom: 16px;
}
/* ── Placeholder cards ── */
.card-placeholder {
height: 64px;
background: var(--surface);
border-radius: 10px;
margin-bottom: 10px;
border: 1px solid rgba(255, 255, 255, 0.04);
}
.search-bar-placeholder {
height: 36px;
background: var(--surface);
border-radius: 8px;
margin-bottom: 12px;
border: 1px solid rgba(255, 255, 255, 0.06);
}
.avatar-placeholder {
width: 60px;
height: 60px;
background: var(--surface);
border-radius: 50%;
border: 2px solid rgba(56, 189, 248, 0.3);
}const sidebar = document.getElementById("sidebar");
const contentArea = document.getElementById("contentArea");
const navBtns = sidebar.querySelectorAll(".nav-btn");
const pages = contentArea.querySelectorAll(".content-page");
function switchPage(pageName) {
navBtns.forEach((btn) => {
btn.classList.toggle("active", btn.dataset.page === pageName);
});
pages.forEach((page) => {
page.classList.toggle("active", page.dataset.content === pageName);
});
}
navBtns.forEach((btn) => {
btn.addEventListener("click", () => {
switchPage(btn.dataset.page);
});
});<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Rectangular Navigation</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="demo">
<h1 class="demo-title">Rectangular Navigation</h1>
<p class="demo-sub">Compact vertical icon sidebar with active indicator.</p>
<div class="phone-frame">
<div class="phone-screen">
<!-- Status bar -->
<div class="status-bar">
<span>9:41</span>
<span class="status-icons">●●●</span>
</div>
<!-- Main layout: sidebar + content -->
<div class="app-layout">
<!-- Vertical icon sidebar -->
<nav class="sidebar" id="sidebar">
<button class="nav-btn active" data-page="home" aria-label="Home">
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/>
<polyline points="9 22 9 12 15 12 15 22"/>
</svg>
</button>
<button class="nav-btn" data-page="search" aria-label="Search">
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="11" cy="11" r="8"/>
<line x1="21" y1="21" x2="16.65" y2="16.65"/>
</svg>
</button>
<button class="nav-btn" data-page="bookmarks" aria-label="Bookmarks">
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M19 21l-7-5-7 5V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z"/>
</svg>
</button>
<button class="nav-btn" data-page="profile" aria-label="Profile">
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/>
<circle cx="12" cy="7" r="4"/>
</svg>
</button>
</nav>
<!-- Content area -->
<div class="content-area" id="contentArea">
<div class="content-page active" data-content="home">
<h2>Home</h2>
<p>Welcome back! Here's your feed.</p>
<div class="card-placeholder"></div>
<div class="card-placeholder"></div>
<div class="card-placeholder"></div>
</div>
<div class="content-page" data-content="search">
<h2>Search</h2>
<p>Find what you're looking for.</p>
<div class="search-bar-placeholder"></div>
<div class="card-placeholder"></div>
</div>
<div class="content-page" data-content="bookmarks">
<h2>Bookmarks</h2>
<p>Your saved items appear here.</p>
<div class="card-placeholder"></div>
<div class="card-placeholder"></div>
</div>
<div class="content-page" data-content="profile">
<h2>Profile</h2>
<p>Manage your account settings.</p>
<div class="avatar-placeholder"></div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>Rectangular Navigation
A compact vertical navigation rail on the left side with icon-only buttons. Always visible and takes minimal screen space.
Features
- Narrow vertical sidebar (icon-only)
- Active state with background highlight
- 4 nav items: Home, Search, Bookmarks, Profile
- Active indicator slides between items
- Content area fills remaining space
How it works
- Sidebar is a fixed-width flex column on the left
- Icon buttons stacked vertically with flex layout
- Active item gets highlighted background
- Click switches active state and updates content area