Skip to main content
InterviewHubPRO
Section Overview
Q10

Question 10 of 50

Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

20%
Svelte & SvelteKit (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

Svelte Scoped CSS: How does the compiler hash styles?

senior LevelCode ExampleSvelte 5

In Simple Words: Inside .svelte files, any <style> block is automatically scoped to that component:

  • The Svelte compiler generates a unique CSS class hash (e.g. svelte-1t5k8q) and appends it to both the CSS selectors and the corresponding HTML elements:
    css
    /* What you write */
    p { color: purple; }
    
    /* What Svelte compiles */
    p.svelte-1t5k8q { color: purple; }
    
  • Styles never bleed into child or parent components. Use :global() for global selectors.