Skip to content

useScopedStyles

biome.json
{
"linter": {
"rules": {
"nursery": {
"useScopedStyles": "error"
}
}
}
}

Enforce that <style> blocks in Vue SFCs have the scoped attribute and that <style> blocks in Astro components do not have the is:global directive.

Vue’s scoped attribute automatically scopes CSS to the component, preventing style leakage and conflicts. Astro’s is:global attribute allows for global styles, but without it, styles are scoped to the component by default.

Style blocks with the module attribute are exempt, as CSS Modules is an alternative scoping mechanism.

<style>
.foo { color: red; }
</style>
code-block.vue:1:1 lint/nursery/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.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

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/nursery/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.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

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>