Bird
Raised Fist0
Svelteframework~20 mins

Preprocessor support (SCSS, PostCSS) in Svelte - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Preprocessor Pro in Svelte
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
How does SCSS nesting affect Svelte component styles?

Consider this Svelte component style block using SCSS:

<style lang="scss">
.parent {
  color: blue;
  .child {
    color: red;
  }
}
</style>

What CSS will be generated and applied to the component?

Svelte
<style lang="scss">
.parent {
  color: blue;
  .child {
    color: red;
  }
}
</style>
A.parent { color: blue; } .child { color: red; }
B.child { color: blue; } .parent { color: red; }
C.parent { color: blue; } .parent .child { color: red; }
D.parent .child { color: blue; } .child { color: red; }
Attempts:
2 left
💡 Hint

Think about how SCSS nesting combines selectors.

📝 Syntax
intermediate
2:00remaining
Which PostCSS syntax is valid in a Svelte style block?

Given a Svelte component using PostCSS, which style block syntax is correct?

A
&lt;style lang="postcss"&gt;
:root {
  --main-color: #06c;
}
&lt;/style&gt;
B
&lt;style lang="postcss"&gt;
@apply --main-color;
&lt;/style&gt;
C
&lt;style lang="css"&gt;
@apply --main-color;
&lt;/style&gt;
D
&lt;style lang="postcss"&gt;
:root {
  --main-color: #06c
}
&lt;/style&gt;
Attempts:
2 left
💡 Hint

PostCSS supports CSS variables and standard CSS syntax.

🔧 Debug
advanced
2:00remaining
Why does this SCSS style not apply in Svelte?

Given this Svelte component style block:

<style lang="scss">
.button {
  color: green;
  &:hover {
    color: darkgreen;
  }
}
</style>

Why does the hover style not work?

Svelte
<style lang="scss">
.button {
  color: green
  &:hover {
    color: darkgreen;
  }
}
</style>
ASvelte does not support nested selectors in SCSS style blocks.
BMissing semicolon after 'color: green' causes SCSS compile error, so hover style is ignored.
CThe hover selector must be written as '.button:hover' outside nesting.
DThe color 'darkgreen' is invalid and ignored by the browser.
Attempts:
2 left
💡 Hint

Check SCSS syntax carefully for missing punctuation.

❓ state_output
advanced
2:00remaining
What is the effect of PostCSS autoprefixer in Svelte styles?

Consider this style block in a Svelte component using PostCSS with autoprefixer enabled:

<style lang="postcss">
.example {
  display: flex;
}
</style>

What CSS will be output to support older browsers?

Svelte
<style lang="postcss">
.example {
  display: flex;
}
</style>
A.example { display: grid; }
B.example { display: flex; }
C.example { display: block; }
D.example { display: -webkit-box; display: -ms-flexbox; display: flex; }
Attempts:
2 left
💡 Hint

Autoprefixer adds vendor prefixes for compatibility.

🧠 Conceptual
expert
3:00remaining
How does Svelte handle scoped styles with SCSS preprocessing?

In Svelte, when using lang="scss" in a style block, how does Svelte ensure styles are scoped only to the component?

ASvelte adds unique data attributes to elements and rewrites SCSS selectors to include these attributes after preprocessing.
BSCSS automatically scopes styles by prefixing selectors with the component name.
CSvelte wraps the component in a shadow DOM to isolate styles when using SCSS.
DSvelte requires manual addition of unique classes in SCSS to scope styles.
Attempts:
2 left
💡 Hint

Think about how Svelte compiles components and styles.

Practice

(1/5)
1. What attribute do you add to a <style> tag in a Svelte component to use SCSS preprocessing?
easy
A. style="scss"
B. type="scss"
C. preprocess="scss"
D. lang="scss"

Solution

  1. Step 1: Understand Svelte style tag syntax

    In Svelte, to enable a CSS preprocessor like SCSS, you add an attribute to the <style> tag.
  2. Step 2: Identify the correct attribute for SCSS

    The correct attribute is lang="scss", which tells Svelte to preprocess styles with SCSS.
  3. Final Answer:

    lang="scss" -> Option D
  4. Quick Check:

    Use lang="scss" for SCSS preprocessing [OK]
Hint: Use lang="scss" on style tag for SCSS [OK]
Common Mistakes:
  • Using type="scss" instead of lang
  • Adding preprocess attribute which is invalid
  • Putting style="scss" which is not recognized
2. Which of the following is the correct way to enable PostCSS in a Svelte component's style block?
easy
A. <style lang="postcss">
B. <style postcss>
C. <style type="postcss">
D. <style preprocess="postcss">

Solution

  1. Step 1: Recall attribute for preprocessors in Svelte

    Svelte uses the lang attribute on the <style> tag to specify preprocessors.
  2. Step 2: Match the correct syntax for PostCSS

    The correct syntax is <style lang="postcss">. Other attributes like type or preprocess are not valid here.
  3. Final Answer:

    <style lang="postcss"> -> Option A
  4. Quick Check:

    Use lang="postcss" to enable PostCSS [OK]
Hint: Remember lang="postcss" for PostCSS styles [OK]
Common Mistakes:
  • Using postcss attribute without lang
  • Using type instead of lang
  • Trying preprocess attribute which is invalid
3. Given this Svelte component style block:
<style lang="scss">
$primary-color: #3498db;
.button {
  color: $primary-color;
  &:hover {
    color: darken($primary-color, 10%);
  }
}
</style>

What will be the color of the button text on hover?
medium
A. #3498db
B. A color 10% darker than #3498db
C. An error because darken() is not supported
D. Transparent

Solution

  1. Step 1: Understand SCSS variable and nesting

    The variable $primary-color is set to #3498db. The nested hover selector uses darken($primary-color, 10%).
  2. Step 2: Know SCSS darken() function behavior

    The darken() function reduces brightness by 10%, so the hover color is a darker shade of #3498db.
  3. Final Answer:

    A color 10% darker than #3498db -> Option B
  4. Quick Check:

    SCSS darken() darkens color by given percent [OK]
Hint: darken() in SCSS darkens color by given percent [OK]
Common Mistakes:
  • Thinking darken() is unsupported in Svelte
  • Assuming hover color stays the same
  • Confusing variable syntax with CSS custom properties
4. You wrote this Svelte style block:
<style lang="scss">
$color: red
.button { color: $color; }
</style>

But your app fails to compile. What is the likely cause?
medium
A. Missing semicolon after '$color: red' declaration
B. lang attribute should be 'sass' instead of 'scss'
C. Variables are not supported in Svelte styles
D. You must import SCSS files separately, not inline

Solution

  1. Step 1: Check SCSS syntax in style block

    The variable declaration $color: red is missing a semicolon at the end, which is required in SCSS.
  2. Step 2: Understand SCSS syntax rules

    SCSS requires semicolons after declarations. Missing it causes a compile error.
  3. Final Answer:

    Missing semicolon after '$color: red' declaration -> Option A
  4. Quick Check:

    SCSS needs semicolons after declarations [OK]
Hint: Check for missing semicolons in SCSS declarations [OK]
Common Mistakes:
  • Using 'sass' instead of 'scss' without changing syntax
  • Thinking variables are unsupported in Svelte styles
  • Assuming SCSS must be imported, not inline
5. You want to use both SCSS variables and PostCSS autoprefixer in a Svelte project. Which setup correctly enables both preprocessors?
hard
A. Use lang="scss" and import PostCSS in the script block
B. Add lang="scss postcss" to the <style> tag
C. Configure svelte.config.js with svelte-preprocess using both scss and postcss options
D. Write SCSS and PostCSS code in separate <style> tags without lang attributes

Solution

  1. Step 1: Understand how to enable multiple preprocessors in Svelte

    Svelte uses svelte-preprocess configured in svelte.config.js to handle multiple preprocessors like SCSS and PostCSS together.
  2. Step 2: Identify correct configuration method

    You must configure svelte-preprocess with both scss and postcss options in svelte.config.js. Adding multiple lang attributes or importing PostCSS in script won't work.
  3. Final Answer:

    Configure svelte.config.js with svelte-preprocess using both scss and postcss options -> Option C
  4. Quick Check:

    Use svelte-preprocess config for multiple preprocessors [OK]
Hint: Use svelte-preprocess config for SCSS and PostCSS [OK]
Common Mistakes:
  • Trying to add multiple lang attributes in style tag
  • Importing PostCSS in script block instead of config
  • Using separate style tags without lang attributes
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard