Svelte Seo Component

A Svelte component that accepts props for common meta tags that allows overriding metadata specifically for Open Graph & Twitter sharing.

Svelte SEO Component

This is a component which can be used to set common meta tags in the head of pages in a Svelte app.

You can set a default title, description, and image in the component itself. When using the component. It is recommended to always pass title and description as props to avoid duplicate titles and metadescriptions. These props will set title & description meta tags, as well as associated Open Graph & Twitter tags.

This component also accepts Open Graph- & Twitter-specific props that will override the generic title and description values if passed.

The logic of the component assumes that the default value for image and alt are set for a global default sharing image. I recommend adding your default share image to the static folder in Sveltekit projects - that's why all of the image props include static in their path.

Here's an example of a very standard instance of the component, assuming that all of the default values have been changed to be relevant to the project:

    title="About Page | MDSvex Starter Blog"
    description="This is a starter Sveltekit blog with support for MDSvex & image optimisation via Vite ImageTools."

If you really wanted to, you could have different titles, descriptions, and images for Search Engines, Facebook, and Twitter 🤷 Here's what that would look like:

    title="Manually Set Title | Website Name"
    ogTitle="Facebook Title | Website Name"
    twitterTitle="Twitter Title | Website Name"
    description="I'm a manually set meta description."
    ogDescription="I will override the og:description tag."
    twitterDescription="I will override the twitter:description tag."
    ogImageAlt="manual alt text for OG image"
    twitterImageAlt="manual alt text for Twitter image"

Top categories

svelte logo

Want a Svelte site built?

Hire a Svelte developer
Loading Svelte Themes