svelte-attr is a library that dynamically changes the attributes of html and body tags with SvelteKit's SSR.
npm install svelte-attr
// src/hooks.server.ts
import type { Handle } from '@sveltejs/kit';
import { svelteAttr } from 'svelte-attr';
export const handle: Handle = async ({ event, resolve }) => {
return svelteAttr(resolve(event));
};
<script lang="ts">
import { HtmlAttr, BodyAttr } from 'svelte-attr';
</script>
<HtmlAttr lang="en" />
<BodyAttr data-theme="dark" />