Skip to content

useScopedStyles (HTML)

Language HTML
biome.json
{
"linter": {
"rules": {
"style": {
"useScopedStyles": "error"
}
}
}
}

Keep component styles scoped in Vue and Astro files.

A Vue single-file component contains its template, script, and styles in one .vue file. Its <style> blocks need the scoped attribute so their selectors apply only to that component. A <style module> block is also accepted because CSS Modules provide their own scoping.

Astro scopes component styles by default. The rule reports is:global because that directive makes the entire style block affect the page globally.

<style>
.foo { color: red; }
</style>
code-block.vue:1:1 lint/style/useScopedStyles  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This <style> block is missing the scoped attribute.

> 1 │ <style>
│ ^^^^^^^
2 │ .foo { color: red; }
3 │ </style>

ℹ In Vue, unscoped styles become global across the entire project. This can lead to unintended side effects and maintenance challenges. Adding the scoped attribute ensures that styles are scoped to this component, preventing style leakage and conflicts.

ℹ Unsafe fix: Add the scoped attribute so the styles will only apply to this component.

1 │ <style·scoped>
│ +++++++
<style is:global>
.foo { color: red; }
</style>
code-block.astro:1:8 lint/style/useScopedStyles  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This is:global directive is making the styles in this block global.

> 1 │ <style is:global>
│ ^^^^^^^^^
2 │ .foo { color: red; }
3 │ </style>

ℹ In Astro, styles are scoped to the component by default. The is:global directive allows for global styles, but it can lead to unintended side effects and maintenance challenges.

ℹ Unsafe fix: Remove the is:global directive so the styles in this block will be scoped to this component.

1 │ <style·is:global>
│ ---------
<style scoped>
.foo { color: red; }
</style>
<style module>
.foo { color: red; }
</style>