Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
let darkmode = $state(false);
</script>

<svelte:html />

<button onclick={() => darkmode = !darkmode}>toggle dark mode</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
let darkmode = $state(false);
</script>

<svelte:html class={darkmode ? 'dark' : 'light'} />

<button onclick={() => darkmode = !darkmode}>toggle dark mode</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
title: <svelte:html>
---

The `<svelte:html>` element allows you to listen to events _and_ set attributes on the `<html>`. This is useful to for example set the `lang` tag dynamically, or to update `class`es that influence the whole page.

Add a conditional `class` attribute to the `<svelte:html>` tag...

```svelte
<!--- file: App.svelte --->
<svelte:html
+++class={darkmode ? 'dark' : 'light'}+++
/>
```

...and click the button to toggle the mode.