Given this Svelte component usage, what will be the background color of the button?
<Button style="background-color: red;" />
Assume the Button component uses --style-props to pass styles.
/* Button.svelte */ <script> export let style = ""; </script> <button style={style}>Click me</button>
Think about how inline styles passed as props affect the element.
The style prop is passed down and applied directly to the button's style attribute, so the background color becomes red.
In Svelte, you want to pass two CSS custom properties --main-color and --padding to a component using --style-props. Which syntax is correct?
Remember how HTML inline styles are written as strings.
Option D uses a valid HTML inline style string with CSS variables separated by semicolons. Option D uses JavaScript object notation, which Svelte supports by converting to inline styles. Option D uses single quotes for the attribute value. Option D misses the semicolon at the end.
Consider this Svelte component that toggles a CSS variable passed as a style prop:
<script>
let isRed = true;
</script>
<div
style={isRed ? '--text-color: red;' : '--text-color: blue;'}
>
<button
on:click={() => isRed = !isRed}
>Toggle Color</button>
<p style="color: var(--text-color);">Colored Text</p>
</div>What color will the "Colored Text" be after clicking the button twice?
Each click toggles the CSS variable between red and blue.
Initial state is red. First click changes to blue. Second click toggles back to red. So after two clicks, the text color is red.
Given this Svelte component usage:
<Card style="background-color: green" />
And the Card.svelte component:
<script>
export let style = "";
</script>
<div style="{style}">Content</div>Why does the background color not appear green?
Check how the style attribute is bound in the component.
The div uses style="{style}" which treats {style} as a string literal, not a variable. It should be style={style} without quotes to bind the variable.
--style-props improve component styling flexibility in Svelte?Choose the best explanation for why passing styles via --style-props is beneficial in Svelte components.
Think about how CSS variables and style props help with theming.
Passing styles as CSS variables lets parent components control appearance without changing the child component code. This supports flexible theming and style overrides.