Skip to content
Nana UI

Layout & Containers

Top Bar

The bar across the top of an app, with places for a title, search, notifications and the account menu. It stays on screen while the page scrolls.

View .md Download

The top bar holds what every page of an app needs within reach: a way back to the navigation, search, and the signed-in user. It has three places. The start holds a sidebar trigger, a title or a breadcrumb. The middle holds search. The end holds notifications, a theme toggle and the account menu. The middle stretches, so the end always sits at the far edge, whether or not there is a middle.

Claims desk
Page content
Claims desk
Page content

Install the package for a versioned dependency:

npm install @nana-tec/ui-components

Or copy the source in and own it:

npx @nana-tec/ui add top-bar --framework web-components
npx @nana-tec/ui add top-bar --framework svelte

Lands in src/lib/components/ui/top-bar/ as NanaTopBar.svelte, styled with Tailwind classes that resolve to the design tokens. Requires Tailwind v4.

Import the autoloader once, in your app's entry point. Every <nana-*> tag then works anywhere, and each component downloads only the first time a page uses it:

import "@nana-tec/ui-components/autoloader";
import "@nana-tec/ui-components/theme";

The second line gives every component the Nana look and the design tokens behind it. Leave it out to style the components entirely yourself.

Import a component directly when it must be ready at once: on screen at first paint, or when you call its methods straight away. The two mix freely:

import "@nana-tec/ui-components/top-bar";

Copied in with npx @nana-tec/ui add top-bar? Import your project's own @/lib/nana-ui/autoloader.js once instead; the CLI keeps it up to date.

Put content in the start and end slots; anything without a slot goes in the middle.

<nana-top-bar>
<nana-sidebar-trigger slot="start"></nana-sidebar-trigger>
<nana-input type="search" aria-label="Search"></nana-input>
<nana-icon-button slot="end" name="bell" label="Notifications"></nana-icon-button>
<nana-dropdown slot="end">…</nana-dropdown>
</nana-top-bar>

Fill the start and end snippets; children go in the middle.

<script lang="ts">
import { NanaTopBar } from '$lib/components/ui/top-bar';
</script>
<NanaTopBar>
{#snippet start()}<NanaSidebarTrigger />{/snippet}
<NanaInput type="search" aria-label="Search" />
{#snippet end()}
<NanaThemeToggle />
<NanaDropdown …></NanaDropdown>
{/snippet}
</NanaTopBar>

Put the top bar first inside the sidebar layout’s page, then the page header and the content. The bar stays at the top while the page scrolls under it, and the sidebar trigger in it works on a phone too.

<nana-sidebar-layout label="Main">
<nana-sidebar-group slot="sidebar" label="Workspace">…</nana-sidebar-group>
<nana-top-bar>
<nana-sidebar-trigger slot="start"></nana-sidebar-trigger>
</nana-top-bar>
<div style="padding: 1.5rem">
<nana-page-header heading="Claims"></nana-page-header>
</div>
</nana-sidebar-layout>
<NanaSidebarLayout label="Main">
<NanaSidebar>…</NanaSidebar>
<NanaSidebarInset>
<NanaTopBar>
{#snippet start()}<NanaSidebarTrigger />{/snippet}
</NanaTopBar>
<div class="p-6"><NanaPageHeader heading="Claims" /></div>
</NanaSidebarInset>
</NanaSidebarLayout>

The bar is sticky by default. Over scrolling content it turns slightly translucent and blurs what passes under it. It sits on the --nana-z-index-sticky layer, which is below menus, dialogs and toasts, so they always open over it. Set --nana-top-bar-z to change its place.

To let the bar scroll away with the page, turn sticky off:

<nana-top-bar sticky="false">…</nana-top-bar>
<NanaTopBar sticky={false}>…</NanaTopBar>
  • The bar is a header. Inside the page’s main it adds no landmark of its own; at the top of the page, outside main, it is the page’s banner.
  • Give every icon-only button a label, such as “Notifications”.
  • Label the search field, even when a placeholder shows, since a placeholder disappears as soon as someone types.

Properties

PropertyAttributeTypeDefaultDescription
stickystickybooleantrueKeeps the bar at the top while the page scrolls. Set sticky="false" to let it scroll away.

Slots

SlotDescription
(default)The middle of the bar, usually a search field
startThe start of the bar, such as a nana-sidebar-trigger and a breadcrumb
endThe end of the bar, such as a theme toggle, notifications and the account menu

CSS parts

PartDescription
::part(base)The bar
::part(start)The wrapper around the start content
::part(center)The wrapper around the middle content
::part(end)The wrapper around the end content

CSS custom properties

PropertyDescription
--nana-top-bar-heightMinimum height of the bar
--nana-top-bar-bgBackground of the bar
--nana-top-bar-zStacking order while sticky

NanaTopBar

PropTypeDefault
stickybooleantrue
startSnippet
endSnippet
childrenSnippet

Also accepts Omit<HTMLAttributes<HTMLElement>, 'class'>.

sticky keeps the bar at the top, on by default. start and end are snippets, and children fill the middle. Other attributes, such as aria-label, go on the header.