Skip to content

Metatags

The head tags one page needs for search results and link previews: title, description, canonical, Open Graph, and an X card. Site-level values are props too, so a small wrapper of your own holds them while each page passes only what changes.

Import

import { Metatags } from "@hyzer-labs/ui"

Demo

This component renders nothing visible. Its whole output is a <svelte:head> block, and rendering it here would put a second <title> into this site's own head, so there is no live preview. Every example below is the exact source, and the last tab shows what it emits. It takes no class prop and forwards no other attributes, because it renders no element to put them on.

Every prop arrives directly on the page that needs it. With no image, the card falls back to twitter:card="summary" and Metatags emits no image tags.

<Metatags
	siteUrl="https://example.com"
	siteName="Example"
	url="/pricing"
	title="Pricing"
	description="Three plans, no seat minimums."
/>

Props

NameTypeDefaultNote
siteUrlstringAbsolute site origin, such as "https://example.com". Any relative url, canonical, or image needs it to resolve to the absolute URL Open Graph requires.
urlstringThis page: a root-relative path ("/pricing") or an absolute URL. In SvelteKit this is page.url.pathname, passed by your own wrapper — see the "Per-site wrapper" demo above.
titlestringThe page title. Composed with siteName into one string shared by <title>, og:title, and twitter:title.
siteNamestringThe site's name. Emits og:site_name and is the title suffix.
titleSeparatorstring' | 'Sits between title and siteName.
descriptionstringSets the description meta tag plus og:description and twitter:description. An empty string counts as unset.
imagestringPreview image, a path or an absolute URL, resolved the same way as url.
imageAltstringAlt text for the preview image. Setting image without it prints a console warning in development.
typestring'website'Sets og:type, emitted as given with no validation. The Open Graph protocol's type list is the reference; 'article' is the other common one.
canonicalstringurlCanonical override for a page reachable at more than one address, path or absolute.
twitterCard'summary' | 'summary_large_image'derived from imagesummary_large_image once an image resolves, summary otherwise.
childrenSnippetRendered last, inside the same head block — for tags this component does not manage (twitter:site, robots, JSON-LD, and the rest), not for overriding the ones it does.

Accessibility

This component has no ARIA, no roles, and no focus behavior. Nothing here is interactive, but two accessibility duties still apply. <title> is the page's accessible name, both in the browser tab and in a screen reader's window list, so this component never emits an empty or invented one: give it a title, a siteName, or both. og:image:alt and twitter:image:alt give the preview image a text alternative in every client that shows one, so setting image without imageAlt prints a development-only warning.

Set a page's title once, either through this component or through the page's own <svelte:head>, never both.

References: The Open Graph protocol · X: cards markup reference · Google: consolidate duplicate URLs with canonical links · WCAG 2.4.2: Page Titled