0
0
Svelteframework~5 mins

CSS custom properties (variables) in Svelte - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What are CSS custom properties (variables)?
CSS custom properties are special values defined by the user that start with --. They store reusable values like colors or sizes, making it easy to change styles in one place.
Click to reveal answer
beginner
How do you define a CSS custom property inside a Svelte component?
You define it inside a CSS selector using --property-name: value;. For example, :root { --main-color: #3498db; } sets a global variable.
Click to reveal answer
beginner
How do you use a CSS custom property in your styles?
Use the var(--property-name) function. For example, color: var(--main-color); applies the value stored in --main-color.
Click to reveal answer
intermediate
Why are CSS custom properties useful in Svelte components?
They let you create flexible styles that can be changed easily. You can update variables dynamically or share them across components for consistent design.
Click to reveal answer
intermediate
Can CSS custom properties be changed with JavaScript in Svelte?
Yes! You can update them by setting styles on elements or document.documentElement. This allows dynamic theming or style changes without rewriting CSS.
Click to reveal answer
How do you declare a CSS custom property?
AUsing <code>@property-name: value;</code>
BUsing <code>$property-name: value;</code>
CUsing <code>property-name: value;</code>
DUsing <code>--property-name: value;</code>
How do you use a CSS custom property in a style rule?
Acolor: $property-name;
Bcolor: var(--property-name);
Ccolor: @property-name;
Dcolor: property-name;
Where can you define global CSS custom properties in a Svelte app?
A:root selector
BInside <script> tag
CInside <style> tag without selector
DInside <main> tag
Can CSS custom properties be changed dynamically with JavaScript?
AOnly with Svelte stores
BNo, they are fixed in CSS
CYes, by setting style properties on elements
DOnly in external CSS files
What is a benefit of using CSS custom properties in Svelte?
AEasier theming and style reuse
BFaster JavaScript execution
CAutomatic component re-rendering
DBuilt-in state management
Explain how to define and use CSS custom properties in a Svelte component.
Think about how you set colors or sizes once and reuse them.
You got /4 concepts.
    Describe how CSS custom properties can be updated dynamically in a Svelte app.
    Consider how you might let users switch color themes.
    You got /3 concepts.