1 GitHub star = 1 new component.

Developer Portfolio

Dev Header

Floating navigation with a split logo that collapses on scroll (N·OALINDQVIST·.DEV → N.DEV), pill links, light/dark toggle and a full-screen mobile menu.

headernavbarportfoliotheme-toggle
Live Preview

Usage

Copy and paste this code into your Astro page:

astro
---
import { DevHeader } from 'astro-component-kit/sections';
---

<DevHeader logo={{ initial: 'K', middle: 'EYCAP', suffix: '.DEV' }} links={[{ label: 'Projects', href: '/projects/' }, { label: 'Blog', href: '/blog/' }]} />
--- import { DevHeader } from 'astro-component-kit/sections'; --- <DevHeader logo={{ initial: 'K', middle: 'EYCAP', suffix: '.DEV' }} links={[{ label: 'Projects', href: '/projects/' }, { label: 'Blog', href: '/blog/' }]} />

Examples in context

Real code from the kit: how this piece is used inside templates, sections and other components.

Template Developer Portfolio PortfolioLayout.astro
astro
<DevHeader logo={site.logo} logoHref={routes.home} links={links} currentHref={currentHref} />
<DevHeader logo={site.logo} logoHref={routes.home} links={links} currentHref={currentHref} />

Used in

Works well with

Manual Installation

If you are not using the npm package, create a new file and paste the following code: src/components/sections/DevHeader.astro:

astro
---
/**
 * DevHeader — Floating navigation for developer portfolios ("Keycap" design): a split logo whose
 * middle collapses on scroll (N·OALINDQVIST·.DEV → N.DEV), pill links, a light/dark toggle and a
 * full-screen mobile menu.
 *
 * @param {{initial: string, middle: string, suffix: string}} logo - Logo parts. Default K / EYCAP / .DEV.
 * @param {string} logoHref - Logo link. Default '/'.
 * @param {Array<{label: string, href: string}>} links - Menu links.
 * @param {string} currentHref - Marks the matching link with aria-current="page".
 * @param {boolean} themeToggle - Show the light/dark toggle. Default true.
 * @param {boolean} collapseOnScroll - Collapse the logo middle after scrolling. Default true.
 * @param {string} className - Extra class.
 *
 * Accessibility: nav landmark with label; the mobile menu is a disclosure (aria-expanded,
 * aria-controls) that closes with Escape and returns focus; 44px touch targets; the theme toggle
 * reports its state with aria-pressed.
 */
interface Props {
  logo?: { initial: string; middle: string; suffix: string };
  logoHref?: string;
  links?: Array<{ label: string; href: string }>;
  currentHref?: string;
  themeToggle?: boolean;
  collapseOnScroll?: boolean;
  className?: string;
}

const {
  logo = { initial: 'K', middle: 'EYCAP', suffix: '.DEV' },
  logoHref = '/',
  links = [{ label: 'Home', href: '/' }, { label: 'Projects', href: '/projects/' }, { label: 'Blog', href: '/blog/' }, { label: 'Contact', href: '/contact/' }],
  currentHref = '/',
  themeToggle = true,
  collapseOnScroll = true,
  className = '',
} = Astro.props;

const isActive = (href: string) => !!currentHref && (currentHref === href || (href !== logoHref && currentHref.startsWith(href)));
const menuId = `dvhd-menu-${Math.random().toString(36).slice(2, 8)}`;
---

<header class:list={['dvhd', className]} data-dev-header data-collapse={collapseOnScroll ? '' : undefined}>
  <div class="dvhd__bar">
    <a class="dvhd__logo" href={logoHref} aria-label={`${logo.initial}${logo.middle}${logo.suffix} — home`}>
      <span class="dvhd__initial">{logo.initial}</span><span class="dvhd__middle" aria-hidden="true">{logo.middle}</span><span class="dvhd__suffix">{logo.suffix}</span>
    </a>

    <nav class="dvhd__nav" aria-label="Main">
      <ul class="dvhd__list" id={menuId}>
        {links.map((l) => (
          <li>
            <a class:list={['dvhd__link', { 'is-active': isActive(l.href) }]} href={l.href} aria-current={isActive(l.href) ? 'page' : undefined}>{l.label}</a>
          </li>
        ))}
      </ul>
    </nav>

    <div class="dvhd__tools">
      {themeToggle && (
        <button class="dvhd__icon" type="button" data-theme-btn aria-label="Dark theme" aria-pressed="false">
          <svg class="dvhd__sun" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"/></svg>
          <svg class="dvhd__moon" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z"/></svg>
        </button>
      )}
      <button class="dvhd__toggle" type="button" data-menu-btn aria-expanded="false" aria-controls={menuId} aria-label="Menu">
        <span></span><span></span>
      </button>
    </div>
  </div>
</header>

<style>
  .dvhd {
    --dvhd-bg: rgb(var(--paper-rgb, 255 255 255) / 0.78);
    position: fixed;
    inset: 0 0 auto;
    z-index: 900;
    padding: 0.85rem clamp(0.75rem, 3vw, 2rem);
    pointer-events: none;
    transition: padding 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  }
  .dvhd.is-scrolled { padding-block: 0.55rem; }
  .dvhd__bar {
    max-width: 1120px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
  }
  .dvhd__logo,
  .dvhd__nav,
  .dvhd__tools { pointer-events: auto; }

  .dvhd__logo {
    display: inline-flex;
    align-items: baseline;
    min-height: 44px;
    align-items: center;
    padding: 0 1.1rem;
    border-radius: 999px;
    background: var(--dvhd-bg);
    backdrop-filter: blur(18px) saturate(180%);
    -webkit-backdrop-filter: blur(18px) saturate(180%);
    box-shadow: 0 8px 28px -10px rgb(var(--ink-rgb, 0 0 0) / 0.18), 0 0 0 1px rgb(var(--ink-rgb, 0 0 0) / 0.06);
    color: var(--c-text-1);
    text-decoration: none;
    font-weight: 800;
    font-size: 1.05rem;
    letter-spacing: -0.02em;
    white-space: nowrap;
  }
  .dvhd__middle {
    display: inline-block;
    max-width: 14ch;
    overflow: hidden;
    vertical-align: bottom;
    transition: max-width 0.45s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.3s ease;
  }
  .dvhd.is-scrolled[data-collapse] .dvhd__middle { max-width: 0; opacity: 0; }
  .dvhd.is-scrolled[data-collapse] .dvhd__logo:hover .dvhd__middle,
  .dvhd.is-scrolled[data-collapse] .dvhd__logo:focus-visible .dvhd__middle { max-width: 14ch; opacity: 1; }

  .dvhd__list {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    list-style: none;
    margin: 0;
    padding: 0.3rem;
    border-radius: 999px;
    background: var(--dvhd-bg);
    backdrop-filter: blur(18px) saturate(180%);
    -webkit-backdrop-filter: blur(18px) saturate(180%);
    box-shadow: 0 8px 28px -10px rgb(var(--ink-rgb, 0 0 0) / 0.18), 0 0 0 1px rgb(var(--ink-rgb, 0 0 0) / 0.06);
  }
  .dvhd__link {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    padding: 0 1rem;
    border-radius: 999px;
    color: var(--c-text-1);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    border: 1px solid transparent;
    transition: background 0.2s ease, border-color 0.2s ease;
  }
  .dvhd__link:hover { background: rgb(var(--ink-rgb, 0 0 0) / 0.05); }
  .dvhd__link.is-active {
    background: rgb(var(--ink-rgb, 0 0 0) / 0.07);
    border-color: rgb(var(--ink-rgb, 0 0 0) / 0.12);
  }

  .dvhd__tools { display: flex; gap: 0.5rem; }
  .dvhd__icon,
  .dvhd__toggle {
    width: 44px;
    height: 44px;
    display: inline-grid;
    place-items: center;
    border-radius: 999px;
    border: 0;
    background: var(--dvhd-bg);
    backdrop-filter: blur(18px) saturate(180%);
    -webkit-backdrop-filter: blur(18px) saturate(180%);
    box-shadow: 0 8px 28px -10px rgb(var(--ink-rgb, 0 0 0) / 0.18), 0 0 0 1px rgb(var(--ink-rgb, 0 0 0) / 0.06);
    color: var(--c-text-1);
    cursor: pointer;
  }
  .dvhd__moon { display: none; }
  :global([data-theme='dark']) .dvhd__sun { display: none; }
  :global([data-theme='dark']) .dvhd__moon { display: block; }

  .dvhd__toggle { display: none; position: relative; }
  .dvhd__toggle span {
    position: absolute;
    left: 13px;
    width: 18px;
    height: 2px;
    border-radius: 2px;
    background: currentColor;
    transition: transform 0.3s ease, top 0.3s ease;
  }
  .dvhd__toggle span:first-child { top: 18px; }
  .dvhd__toggle span:last-child { top: 24px; }
  .dvhd__toggle[aria-expanded='true'] span:first-child { top: 21px; transform: rotate(45deg); }
  .dvhd__toggle[aria-expanded='true'] span:last-child { top: 21px; transform: rotate(-45deg); }

  .dvhd :focus-visible { outline: 2px solid var(--c-text-1); outline-offset: 3px; }

  @media (max-width: 768px) {
    .dvhd__toggle { display: inline-grid; }
    .dvhd__nav { position: static; }
    .dvhd__list {
      position: fixed;
      inset: 0;
      z-index: -1;
      flex-direction: column;
      justify-content: center;
      gap: 0.75rem;
      border-radius: 0;
      padding: 5rem 1.5rem 2rem;
      background: var(--c-bg);
      box-shadow: none;
      opacity: 0;
      visibility: hidden;
      transform: translateY(-12px);
      transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s;
    }
    .dvhd.is-open .dvhd__list { opacity: 1; visibility: visible; transform: none; }
    .dvhd__link { font-size: 1.6rem; font-weight: 700; min-height: 56px; padding: 0 1.5rem; }
  }
  @media (prefers-reduced-motion: reduce) {
    .dvhd, .dvhd__middle, .dvhd__list, .dvhd__toggle span { transition: none; }
  }
</style>

<script>
  document.querySelectorAll<HTMLElement>('[data-dev-header]:not([data-bound])').forEach((h) => {
    h.dataset.bound = '';
    const onScroll = () => h.classList.toggle('is-scrolled', window.scrollY > 80);
    onScroll();
    window.addEventListener('scroll', onScroll, { passive: true });

    const btn = h.querySelector<HTMLButtonElement>('[data-menu-btn]');
    const setOpen = (open: boolean) => {
      h.classList.toggle('is-open', open);
      btn?.setAttribute('aria-expanded', String(open));
      document.documentElement.style.overflow = open ? 'hidden' : '';
    };
    btn?.addEventListener('click', () => setOpen(btn.getAttribute('aria-expanded') !== 'true'));
    h.querySelectorAll('.dvhd__link').forEach((a) => a.addEventListener('click', () => setOpen(false)));
    document.addEventListener('keydown', (e) => {
      if (e.key === 'Escape' && h.classList.contains('is-open')) {
        setOpen(false);
        btn?.focus();
      }
    });

    const themeBtn = h.querySelector<HTMLButtonElement>('[data-theme-btn]');
    const sync = () => {
      const dark = document.documentElement.dataset.theme === 'dark';
      themeBtn?.setAttribute('aria-pressed', String(dark));
    };
    sync();
    themeBtn?.addEventListener('click', () => {
      const next = document.documentElement.dataset.theme === 'dark' ? 'light' : 'dark';
      document.documentElement.dataset.theme = next;
      try { window.localStorage.setItem('ack-theme', next); } catch { /* ignore */ }
      sync();
    });
  });
</script>
--- /** * DevHeader — Floating navigation for developer portfolios ("Keycap" design): a split logo whose * middle collapses on scroll (N·OALINDQVIST·.DEV → N.DEV), pill links, a light/dark toggle and a * full-screen mobile menu. * * @param {{initial: string, middle: string, suffix: string}} logo - Logo parts. Default K / EYCAP / .DEV. * @param {string} logoHref - Logo link. Default '/'. * @param {Array<{label: string, href: string}>} links - Menu links. * @param {string} currentHref - Marks the matching link with aria-current="page". * @param {boolean} themeToggle - Show the light/dark toggle. Default true. * @param {boolean} collapseOnScroll - Collapse the logo middle after scrolling. Default true. * @param {string} className - Extra class. * * Accessibility: nav landmark with label; the mobile menu is a disclosure (aria-expanded, * aria-controls) that closes with Escape and returns focus; 44px touch targets; the theme toggle * reports its state with aria-pressed. */ interface Props { logo?: { initial: string; middle: string; suffix: string }; logoHref?: string; links?: Array<{ label: string; href: string }>; currentHref?: string; themeToggle?: boolean; collapseOnScroll?: boolean; className?: string; } const { logo = { initial: 'K', middle: 'EYCAP', suffix: '.DEV' }, logoHref = '/', links = [{ label: 'Home', href: '/' }, { label: 'Projects', href: '/projects/' }, { label: 'Blog', href: '/blog/' }, { label: 'Contact', href: '/contact/' }], currentHref = '/', themeToggle = true, collapseOnScroll = true, className = '', } = Astro.props; const isActive = (href: string) => !!currentHref && (currentHref === href || (href !== logoHref && currentHref.startsWith(href))); const menuId = `dvhd-menu-${Math.random().toString(36).slice(2, 8)}`; --- <header class:list={['dvhd', className]} data-dev-header data-collapse={collapseOnScroll ? '' : undefined}> <div class="dvhd__bar"> <a class="dvhd__logo" href={logoHref} aria-label={`${logo.initial}${logo.middle}${logo.suffix} — home`}> <span class="dvhd__initial">{logo.initial}</span><span class="dvhd__middle" aria-hidden="true">{logo.middle}</span><span class="dvhd__suffix">{logo.suffix}</span> </a> <nav class="dvhd__nav" aria-label="Main"> <ul class="dvhd__list" id={menuId}> {links.map((l) => ( <li> <a class:list={['dvhd__link', { 'is-active': isActive(l.href) }]} href={l.href} aria-current={isActive(l.href) ? 'page' : undefined}>{l.label}</a> </li> ))} </ul> </nav> <div class="dvhd__tools"> {themeToggle && ( <button class="dvhd__icon" type="button" data-theme-btn aria-label="Dark theme" aria-pressed="false"> <svg class="dvhd__sun" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"/></svg> <svg class="dvhd__moon" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z"/></svg> </button> )} <button class="dvhd__toggle" type="button" data-menu-btn aria-expanded="false" aria-controls={menuId} aria-label="Menu"> <span></span><span></span> </button> </div> </div> </header> <style> .dvhd { --dvhd-bg: rgb(var(--paper-rgb, 255 255 255) / 0.78); position: fixed; inset: 0 0 auto; z-index: 900; padding: 0.85rem clamp(0.75rem, 3vw, 2rem); pointer-events: none; transition: padding 0.3s cubic-bezier(0.16, 1, 0.3, 1); } .dvhd.is-scrolled { padding-block: 0.55rem; } .dvhd__bar { max-width: 1120px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 1rem; } .dvhd__logo, .dvhd__nav, .dvhd__tools { pointer-events: auto; } .dvhd__logo { display: inline-flex; align-items: baseline; min-height: 44px; align-items: center; padding: 0 1.1rem; border-radius: 999px; background: var(--dvhd-bg); backdrop-filter: blur(18px) saturate(180%); -webkit-backdrop-filter: blur(18px) saturate(180%); box-shadow: 0 8px 28px -10px rgb(var(--ink-rgb, 0 0 0) / 0.18), 0 0 0 1px rgb(var(--ink-rgb, 0 0 0) / 0.06); color: var(--c-text-1); text-decoration: none; font-weight: 800; font-size: 1.05rem; letter-spacing: -0.02em; white-space: nowrap; } .dvhd__middle { display: inline-block; max-width: 14ch; overflow: hidden; vertical-align: bottom; transition: max-width 0.45s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.3s ease; } .dvhd.is-scrolled[data-collapse] .dvhd__middle { max-width: 0; opacity: 0; } .dvhd.is-scrolled[data-collapse] .dvhd__logo:hover .dvhd__middle, .dvhd.is-scrolled[data-collapse] .dvhd__logo:focus-visible .dvhd__middle { max-width: 14ch; opacity: 1; } .dvhd__list { display: flex; align-items: center; gap: 0.35rem; list-style: none; margin: 0; padding: 0.3rem; border-radius: 999px; background: var(--dvhd-bg); backdrop-filter: blur(18px) saturate(180%); -webkit-backdrop-filter: blur(18px) saturate(180%); box-shadow: 0 8px 28px -10px rgb(var(--ink-rgb, 0 0 0) / 0.18), 0 0 0 1px rgb(var(--ink-rgb, 0 0 0) / 0.06); } .dvhd__link { display: inline-flex; align-items: center; min-height: 40px; padding: 0 1rem; border-radius: 999px; color: var(--c-text-1); text-decoration: none; font-size: 0.9rem; font-weight: 500; border: 1px solid transparent; transition: background 0.2s ease, border-color 0.2s ease; } .dvhd__link:hover { background: rgb(var(--ink-rgb, 0 0 0) / 0.05); } .dvhd__link.is-active { background: rgb(var(--ink-rgb, 0 0 0) / 0.07); border-color: rgb(var(--ink-rgb, 0 0 0) / 0.12); } .dvhd__tools { display: flex; gap: 0.5rem; } .dvhd__icon, .dvhd__toggle { width: 44px; height: 44px; display: inline-grid; place-items: center; border-radius: 999px; border: 0; background: var(--dvhd-bg); backdrop-filter: blur(18px) saturate(180%); -webkit-backdrop-filter: blur(18px) saturate(180%); box-shadow: 0 8px 28px -10px rgb(var(--ink-rgb, 0 0 0) / 0.18), 0 0 0 1px rgb(var(--ink-rgb, 0 0 0) / 0.06); color: var(--c-text-1); cursor: pointer; } .dvhd__moon { display: none; } :global([data-theme='dark']) .dvhd__sun { display: none; } :global([data-theme='dark']) .dvhd__moon { display: block; } .dvhd__toggle { display: none; position: relative; } .dvhd__toggle span { position: absolute; left: 13px; width: 18px; height: 2px; border-radius: 2px; background: currentColor; transition: transform 0.3s ease, top 0.3s ease; } .dvhd__toggle span:first-child { top: 18px; } .dvhd__toggle span:last-child { top: 24px; } .dvhd__toggle[aria-expanded='true'] span:first-child { top: 21px; transform: rotate(45deg); } .dvhd__toggle[aria-expanded='true'] span:last-child { top: 21px; transform: rotate(-45deg); } .dvhd :focus-visible { outline: 2px solid var(--c-text-1); outline-offset: 3px; } @media (max-width: 768px) { .dvhd__toggle { display: inline-grid; } .dvhd__nav { position: static; } .dvhd__list { position: fixed; inset: 0; z-index: -1; flex-direction: column; justify-content: center; gap: 0.75rem; border-radius: 0; padding: 5rem 1.5rem 2rem; background: var(--c-bg); box-shadow: none; opacity: 0; visibility: hidden; transform: translateY(-12px); transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s; } .dvhd.is-open .dvhd__list { opacity: 1; visibility: visible; transform: none; } .dvhd__link { font-size: 1.6rem; font-weight: 700; min-height: 56px; padding: 0 1.5rem; } } @media (prefers-reduced-motion: reduce) { .dvhd, .dvhd__middle, .dvhd__list, .dvhd__toggle span { transition: none; } } </style> <script> document.querySelectorAll<HTMLElement>('[data-dev-header]:not([data-bound])').forEach((h) => { h.dataset.bound = ''; const onScroll = () => h.classList.toggle('is-scrolled', window.scrollY > 80); onScroll(); window.addEventListener('scroll', onScroll, { passive: true }); const btn = h.querySelector<HTMLButtonElement>('[data-menu-btn]'); const setOpen = (open: boolean) => { h.classList.toggle('is-open', open); btn?.setAttribute('aria-expanded', String(open)); document.documentElement.style.overflow = open ? 'hidden' : ''; }; btn?.addEventListener('click', () => setOpen(btn.getAttribute('aria-expanded') !== 'true')); h.querySelectorAll('.dvhd__link').forEach((a) => a.addEventListener('click', () => setOpen(false))); document.addEventListener('keydown', (e) => { if (e.key === 'Escape' && h.classList.contains('is-open')) { setOpen(false); btn?.focus(); } }); const themeBtn = h.querySelector<HTMLButtonElement>('[data-theme-btn]'); const sync = () => { const dark = document.documentElement.dataset.theme === 'dark'; themeBtn?.setAttribute('aria-pressed', String(dark)); }; sync(); themeBtn?.addEventListener('click', () => { const next = document.documentElement.dataset.theme === 'dark' ? 'light' : 'dark'; document.documentElement.dataset.theme = next; try { window.localStorage.setItem('ack-theme', next); } catch { /* ignore */ } sync(); }); }); </script>
Part of a complete template

This section was crafted as a core block for the following template. You can preview the full interactive multi-page experience or explore all related components.

Full templates 6 pages · 15 components

Developer Portfolio

A monochrome, keyboard-inspired portfolio with 3D projects, a typing keyboard and a contribution matrix of flying cubes.

More Sections to Explore

Discover other full-width landing blocks and production-ready sections from our library.

All sections