Bottom navigation
A bar of three to five top-level destinations along the bottom of a phone screen.
Example
<focsd-bottom-nav position="static" hide-above="0" label="Main"> <focsd-bottom-nav-item href="#home" icon="home" label="Home" current></focsd-bottom-nav-item> <focsd-bottom-nav-item href="#search" icon="search" label="Search"></focsd-bottom-nav-item> <focsd-bottom-nav-item href="#inbox" icon="inbox" label="Inbox" badge="3"></focsd-bottom-nav-item> <focsd-bottom-nav-item href="#profile" icon="user" label="Profile"></focsd-bottom-nav-item></focsd-bottom-nav>Usage
Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.
<script type="module"> import '@focsd-dev/components/focsd-bottom-nav.js';</script>
<focsd-bottom-nav position="static" hide-above="0" label="Main">…</focsd-bottom-nav>import { BottomNav } from '@focsd-dev/react';
export function Example() { return <BottomNav position="static" hide-above="0" label="Main">…</BottomNav>;}<script setup>import '@focsd-dev/components/focsd-bottom-nav.js';</script>
<template> <focsd-bottom-nav position="static" hide-above="0" label="Main">…</focsd-bottom-nav></template>// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:import '@focsd-dev/components/focsd-bottom-nav.js';
// template<focsd-bottom-nav position="static" hide-above="0" label="Main">…</focsd-bottom-nav><script> import '@focsd-dev/components/focsd-bottom-nav.js';</script>
<focsd-bottom-nav position="static" hide-above="0" label="Main">…</focsd-bottom-nav>API
Attributes
| Attribute | Property | Type | Default |
|---|---|---|---|
label | label | string | — |
position | position | 'fixed' | 'sticky' | 'static' | fixed |
hide-above | hideAbove | number | HIDE_ABOVE |
Slots
| Slot | Description |
|---|---|
(default) | The focsd-bottom-nav-item elements. |
CSS parts
Style the inside of the component with ::part(), for example focsd-bottom-nav::part(nav).
| Part | Description |
|---|---|
nav | The nav element. |
list | The list element. |
Accessibility
- A navigation landmark named "Main" (set
labelfor another name) holding real links. Open in a new tab, copy the address and modifier clicks all work, and without JavaScript each one still goes to its page. - The current item has
aria-current="page", and is shown with a heavier label and a bar above it, so it is never only a color. In forced colors it gets an outline. - A
badgejoins the link's name, so a screen reader hears "Inbox, 3 new", not a bare 3. The visible badge is hidden from assistive technology. - Items are at least 48 px wide and tall. On a phone with a home indicator the bar pads itself by the safe-area inset.
- Use three to five items. Fewer or more logs a warning, because more than five crowds the targets.
- It shows below 768 px by default and hides on wider screens (
hide-above, in px; 0 never hides). Give wider screens a sidebar or a header navigation instead. - Fixed to the bottom by default, the element keeps the bar's height in the page, so the last of your content is never covered.
position="sticky"and"static"are the alternatives. - Place the bar last in the page, after all other content. Placed first, the space it keeps is at the top and the bar covers the last content.
- A fixed bar covers what scrolls under it, so a focused element could end up hidden behind it (WCAG 2.4.11). Set
scroll-padding-block-endonhtmlto the bar's height:calc(var(--focsd-bottom-nav-height, 4rem) + env(safe-area-inset-bottom)). The component cannot set it from inside its shadow root. - To use a client-side router, register it once with
setLinkHandler, as in the router recipes.
Keyboard
| Key | Action |
|---|---|
| Tab | Move between the links |
| Enter | Follow the focused link |
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.