Learning Svelte styling: the resources I am using
Where to learn how Svelte styles components, from the official tutorial to videos, plus the playground experiments that finally made scoped styles click for me.

Svelte's scoped styles confused me for a while. Why did a rule in my page not reach a component inside it? Why did a rule for something I passed into a card still apply? I wrote down how scoping works, and this is the list of what I'm using to learn it properly.
Scoping works the same way since Svelte 3, so older material still applies. The one change in Svelte 5 is specificity: the extra parts of a scoped selector are wrapped in :where(), so they add nothing.
Start here
- Svelte tutorial: Styling. The official interactive tutorial. Every step is a small editor with a result next to it, and the lessons that follow cover
:global, theclassattribute and passing styles to components. - Svelte docs: Scoped styles and Global styles. Short reference pages: what the compiler does, specificity,
:global(…)and the:global { … }block. - Svelte docs: Custom properties. Passing values like
--accent="red"to a component, and the wrapper element that holds them.
A course
- Joy of Code: The Complete Svelte 5 Course. Written, not a video, and up to date with Svelte 5. Its styling part covers scoped styles,
:global, the nested:global { … }block, andarticle :global { … }to style everything inside one element.
Videos
- "Styling in Svelte". Scoped CSS first, then
:globalto opt out. - "Scoped Styles In Svelte With The Style Tag". A general introduction to the
<style>block. - "Svelte - Global CSS". Short, only about
:global. - "Master Styling In Svelte 5". Longer, and Svelte 5 specific.
Try it yourself
What made it click was the Svelte playground. It compiles as you type, and the CSS output and JS output tabs show exactly what the compiler did. Three experiments:
- Where the class goes. A page with a
<p>and a child component that renders an<h2>. Add a rule for each in the page's<style>. Theh2rule is marked(unused): the heading is written in the child, so it never gets the page's class. - Children belong to the parent. Pass
<span class="new">into a card as children. A.newrule in the page styles it, even though it shows up inside the card. Move the rule into the card and it stops working. - Custom properties. Render the same card with
--accent="red"and--accent="blue", and have the card usevar(--accent, orange). Inspect the result: both cards have the same scoped class, and each sits in a<svelte-css-wrapper style="display: contents; --accent: …">. Scoping decides which elements a rule matches; the custom property only changes a value it uses.
Related, not Svelte-specific
- MDN: :where(). Why the extra scoped classes add no specificity.
- MDN: @layer. In my site, global styles live in cascade layers and component styles don't, so a component's style always wins. That matters more than specificity.
- MDN: Using CSS custom properties. How the values inherit through the wrapper.