๐ŸŒŠ Unhead v3 is here

The full stack <head> package for any framework.

Unhead wraps your document template, improving reactive SSR JavaScript framework SEO and performance.

Unhead Principles

Why Unhead

01

Complete Developer Experience

  • useHead() with type narrowing, deduping, and tag merging
  • Flat useSeoMeta() for 100+ meta tags
  • useScript() for performant third party loading
  • useSchemaOrg() for automatic Schema.org graphs
  • Plugins for tag validation, canonical URLs, and 7 more
02

Built for Performance

  • ~4.4kb gzipped, tree shakable utilities
  • Built in HTML minification
  • Streaming SSR with head tags pushed per chunk
  • Automatic Capo.js head tag ordering
03

Any Framework / Any Bundler

  • Vue, React, Solid.js, Svelte, and Angular
  • Vite, Webpack, Rollup, and more
  • Built in Vite Devtools integration
  • Hook into every stage of head resolution

Hello useHead()

Unhead aims to provide bullet-proof primitives for a minimal yet powerful API surface.

โœ… Titles that just work

useHead({
  title: 'Hello World',
  titleTemplate: '%s %separator My App',
})
// Hello World - My App

โœ… DOM Events

useHead({
  script: [{
    src: '/script.js',
    onload: () => alert('woo'),
  }],
})

โœ… Classes and styles however you like

useHead({
  bodyAttrs: {
    // use strings
    style: 'background-color: #343434',
    // arrays
    class: ['dark', 'overflow'],
  },
  htmlAttrs: {
    // objects
    style: {
      backgroundColor: 'white',
      color: 'black',
    },
    // computed boolean objects
    class: {
      dark: () => Date.now() % 2 === 0,
    },
  },
})

Built For Reactive Lifecycles

All side effects are tracked so that unmounting a component will revert its head modifications and reactive updates can be made at any time.
useHead({
  title: 'Subscribe now!',
  htmlAttrs: {
    class: { dark: true, light: false }
  },
  bodyAttrs: {
    'style': { overflow: 'hidden' },
    'data-modal': true,
  },
  link: [{
    rel: 'preload',
    href: 'https://3p.com/subscribe.js',
    as: 'script',
  }],
})
Component Not Mounted

Optimized SEO Tags

Nail your SEO with foolproof flat meta config and the simplest Schema.org you've ever worked with.

Flat SEO Meta

Was it <meta property or <meta name? Who can remember, just use useSeoMeta().

useSeoMeta({
  ogType: 'article',
  author: 'Harlan Wilton',
  articleAuthor: ['Harlan Wilton'],
  articlePublishedTime: '2024-01-01',
  articleModifiedTime: '2024-01-01',
  twitterData1: 'Harlan Wilton',
  twitterLabel1: 'Author',
  twitterData2: '10 min',
  twitterLabel2: 'Read Time',
})

Schema.org Graphs

Rich result optimized Schema.org graphs without the application/ld+json.

useSchemaOrg([
  definePerson({
    name: 'Harlan Wilton',
    sameAs: [
      'https://github.com/harlan-zw',
    ],
    url: 'https://harlanzw.com',
  }),
  defineArticle({
    headline: 'Hello World',
    datePublished: '2024-01-01',
  }),
])

Making Websites Faster

Unhead ships to be tree shaken with client and server export paths.

Optimized Head tag ordering

Unhead ships with a default head tag order that is optimized for SEO and performance.

A <script> for full stack javascript

Better developer experience, performance and privacy.

const script = useScript({
  src: 'https://js.cdn/tracker.js',
}, {
  trigger: useOnIdle()
})
script.onError((error) => { /* uh oh */ })
// proxy function calls for when the script is loaded
script.proxy.track('foo')
// or just use onLoaded
script.onLoaded((api) => {
  api.track('bar')
})

โœ… Optimized Client Bundles

// Unhead tags are built to tree-shake, it just works
if (import.meta.server) {
  useHead({
    meta: [{
      name: 'description',
      content: 'Hello World',
    }],
    script: [{
      innerHTML: 'console.log("Hello World")',
    }],
  })
}

Up To Date. Always.

Unhead was started at the end of 2022 and has received continuous bug fixes and feature improvements from the community.

GitHub User harlan-zwGitHub User TheAlexLichterGitHub User BarbapapazesGitHub User danielroeGitHub User dargmuesliGitHub User huang-julienGitHub User LittleSoundGitHub User negezorGitHub User vetruvetGitHub User s-en-oGitHub User NarixiusGitHub User 719mediaGitHub User VloeckGitHub User TimJohnsGitHub User thomasbntGitHub User atinuxGitHub User stvnwGitHub User spnc-omzGitHub User Roman3349GitHub User gangsthubGitHub User nozomuikutaGitHub User NikSimonovGitHub User mukundshahGitHub User maximepvrtGitHub User williamchongGitHub User mittalyashuGitHub User amplitudesxdGitHub User kfreezenGitHub User nWackyGitHub User reslearGitHub User samenickGitHub User t0yoheiGitHub User wckgoGitHub User YunYouJunGitHub User censujiangGitHub User abbassiddiqiGitHub User Mini-ghostGitHub User NyllREGitHub User paraboulGitHub User antfuGitHub User arashsheydaGitHub User bogdanciucaGitHub User TheKickerGitHub User danbarsGitHub User daniluk4000GitHub User EduardF1GitHub User cybe4sent1nelGitHub User felixranesbergerGitHub User imgtaGitHub User HigherOrderLogicGitHub User toto6038GitHub User IngramzGitHub User alcalynGitHub User kricsleoGitHub User cernymatejGitHub User messenjerGitHub User panstromekGitHub User onmax
2.3K
Commits
225
Issues Closed
58
Contributors
348K downloads
per day, on average

Unhead is used and trusted by thousands of developers and companies around the world.

11M
Downloads
/ month
1288
Total Stars

Funded by the community

Unhead is completely free and open-source due to the generous support of the community.

Top Sponsors
Gold Sponsors
Backers