Toggle navigation
☰
Home
HTML
CSS
Scripting
Database
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>The Icon-Only Navbar</title> <style> /* ======================================== CSS Custom Properties (App Theme) ======================================== */ :root { --color-background: #f8f9fa; --color-navbar-bg: #ffffff; --color-icon-default: #6c757d; --color-icon-hover: #007bff; --color-icon-active: #007bff; --color-tooltip-bg: #343a40; --color-tooltip-text: #ffffff; --color-border: #dee2e6; --navbar-height: 70px; --transition-speed: 0.2s; --font-family-sans-serif: system-ui, -apple-system, sans-serif; } /* ======================================== Base & Page Styles ======================================== */ *, *::before, *::after { box-sizing: border-box; } body { margin: 0; font-family: var(--font-family-sans-serif); background-color: var(--color-background); } .content { height: 200vh; padding: calc(var(--navbar-height) + 2rem) 1.5rem; text-align: center; } /* ======================================== Main Navbar Structure ======================================== */ .navbar { height: var(--navbar-height); display: flex; justify-content: center; /* Center the icons container */ align-items: center; position: sticky; top: 0; z-index: 1000; background-color: var(--color-navbar-bg); border-bottom: 1px solid var(--color-border); } .navbar__nav { list-style: none; margin: 0; padding: 0; display: flex; gap: 1rem; } .nav-item__link { position: relative; /* Anchor for the tooltip */ display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; /* Accessible tap target size */ color: var(--color-icon-default); border-radius: 50%; transition: color var(--transition-speed) ease, background-color var(--transition-speed) ease; } .nav-item__link svg { width: 24px; height: 24px; } /* --- Hover, Active, and Focus States --- */ .nav-item__link:hover { color: var(--color-icon-hover); background-color: rgba(0, 123, 255, 0.1); } .nav-item__link.is-active { color: var(--color-icon-active); } .nav-item__link:focus-visible { outline: 2px solid var(--color-icon-hover); outline-offset: 2px; } /* ======================================== Tooltip Styles (Pure CSS) ======================================== */ .nav-item__link::before, .nav-item__link::after { position: absolute; left: 50%; transform: translateX(-50%); /* Hidden by default */ opacity: 0; visibility: hidden; pointer-events: none; /* Can't interact with the tooltip */ transition: opacity var(--transition-speed) ease, transform var(--transition-speed) ease; } /* The tooltip text bubble */ .nav-item__link::before { content: attr(aria-label); /* The tooltip text comes from the aria-label */ top: calc(100% + 23px); padding: 0.5em 0.75em; width: max-content; /* Auto-adjust width to content */ border-radius: 4px; background-color: var(--color-tooltip-bg); color: var(--color-tooltip-text); font-size: 0.875rem; font-weight: 500; } /* The small triangle pointing up */ .nav-item__link::after { content: ''; top: calc(100% + 13px); /* Position it just above the text bubble */ border: 5px solid transparent; border-bottom-color: var(--color-tooltip-bg); color: var(--color-tooltip-bg); } /* Show the tooltip on hover and focus */ .nav-item__link:hover::before, .nav-item__link:hover::after, .nav-item__link:focus::before, .nav-item__link:focus::after { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(-4px); /* A slight upward animation */ } </style> </head> <body> <header class="navbar"> <nav> <ul class="navbar__nav"> <li> <a href="#" class="nav-item__link is-active" aria-label="Home"> <svg viewBox="0 0 24 24"><path fill="currentColor" d="M10,20V14H14V20H19V12H22L12,3L2,12H5V20H10Z" /></svg> </a> </li> <li> <a href="#" class="nav-item__link" aria-label="Explore"> <svg viewBox="0 0 24 24"><path fill="currentColor" d="M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M8.9,11.5L10,8.1L11.1,11.5L14.5,12.6L11.1,13.7L10,17.1L8.9,13.7L5.5,12.6L8.9,11.5Z" /></svg> </a> </li> <li> <a href="#" class="nav-item__link" aria-label="Search"> <svg viewBox="0 0 24 24"><path fill="currentColor" d="M9.5,3A6.5,6.5 0 0,1 16,9.5C16,11.11 15.41,12.59 14.44,13.73L14.71,14H15.5L20.5,19L19,20.5L14,15.5V14.71L13.73,14.44C12.59,15.41 11.11,16 9.5,16A6.5,6.5 0 0,1 3,9.5A6.5,6.5 0 0,1 9.5,3M9.5,5C7,5 5,7 5,9.5C5,12 7,14 9.5,14C12,14 14,12 14,9.5C14,7 12,5 9.5,5Z" /></svg> </a> </li> <li> <a href="#" class="nav-item__link" aria-label="Notifications"> <svg viewBox="0 0 24 24"><path fill="currentColor" d="M10 21H14C14 22.1 13.1 23 12 23S10 22.1 10 21M21 19V20H3V19L5 17V11C5 7.9 7 5.2 10 4.3V4C10 2.9 10.9 2 12 2S14 2.9 14 4V4.3C17 5.2 19 7.9 19 11V17L21 19Z" /></svg> </a> </li> <li> <a href="#" class="nav-item__link" aria-label="Profile"> <svg viewBox="0 0 24 24"><path fill="currentColor" d="M12,12A5,5 0 0,0 17,7A5,5 0 0,0 12,2A5,5 0 0,0 7,7A5,5 0 0,0 12,12M12,14C9.33,14 4,15.33 4,18V20H20V18C20,15.33 14.67,14 12,14Z" /></svg> </a> </li> </ul> </nav> </header> <main class="content"> <h1>Icon-Only Navbar</h1> <p>Hover or focus on an icon to see its descriptive tooltip.</p> </main> </body> </html>