Basic Svelte
Introduction
Bindings
Advanced Svelte
Advanced reactivity
Motion
Advanced bindings
Advanced transitions
Context API
Special elements
<script module>
Next steps
Basic SvelteKit
Introduction
Routing
Loading data
Headers and cookies
Shared modules
API routes
$app/state
Errors and redirects
Advanced SvelteKit
Page options
Link options
Advanced routing
Advanced loading
Environment variables
Conclusion
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...
App
<svelte:html
class={darkmode ? 'dark' : 'light'}
/>
...and click the button to toggle the mode.
previous next
1
2
3
4
5
6
7
8
<script>
let darkmode = $state(false);
</script>
<svelte:html />
<button onclick={() => darkmode = !darkmode}>toggle dark mode</button>