Astro is known for efficient style handling. What is the main way Astro optimizes CSS loading?
Think about how Astro reduces unused CSS on each page.
Astro analyzes which CSS is actually used on each page and inlines only that CSS during build time. This reduces the amount of CSS sent to the browser, improving load speed and efficiency.
Consider an Astro project with multiple components, each with their own styles. What does Astro do with styles that are not used on the current page?
Think about how Astro keeps pages lightweight.
Astro removes unused CSS from the final output so the browser only downloads styles needed for that page. This reduces page size and improves performance.
Which of the following code snippets correctly adds scoped CSS styles inside an Astro component?
<!-- Example Astro component snippets -->
Astro automatically scopes styles inside components without extra attributes.
In Astro, styles inside a component's <style> tag are scoped automatically. Adding 'scoped' attribute is not needed and not supported. Using lang="css" is optional but valid.
At what stage does Astro apply component styles to the HTML during the build and runtime?
Consider Astro's focus on static site generation.
Astro extracts and inlines styles during build time, so the HTML sent to the browser already contains the necessary CSS. This avoids runtime style injection and improves performance.
Given this Astro component code, why might the styles not appear on the page?
<style scoped>
h1 { color: blue; }
</style>
<h1>Hello Astro</h1>Check Astro's style scoping rules and supported attributes.
Astro automatically scopes styles inside components. Using the 'scoped' attribute on the <style> tag is not supported and causes the styles to be ignored, resulting in no styles applied.