# SFC CSS Features ## Scoped CSS When a ` ``` Into the following: ```vue ``` ### Child Component Root Elements With `scoped`, the parent component's styles will not leak into child components. However, a child component's root node will be affected by both the parent's scoped CSS and the child's scoped CSS. This is by design so that the parent can style the child root element for layout purposes. ### Deep Selectors If you want a selector in `scoped` styles to be "deep", i.e. affecting child components, you can use the `:deep()` pseudo-class: ```vue ``` The above will be compiled into: ```css .a[data-v-f3f3eg9] .b { /* ... */ } ``` :::tip DOM content created with `v-html` are not affected by scoped styles, but you can still style them using deep selectors. ::: ### Slotted Selectors By default, scoped styles do not affect contents rendered by ``, as they are considered to be owned by the parent component passing them in. To explicitly target slot content, use the `:slotted` pseudo-class: ```vue ``` ### Global Selectors If you want just one rule to apply globally, you can use the `:global` pseudo-class rather than creating another ` ``` ### Mixing Local and Global Styles You can also include both scoped and non-scoped styles in the same component: ```vue ``` ### Scoped Style Tips - **Scoped styles do not eliminate the need for classes**. Due to the way browsers render various CSS selectors, `p { color: red }` will be many times slower when scoped (i.e. when combined with an attribute selector). If you use classes or ids instead, such as in `.example { color: red }`, then you virtually eliminate that performance hit. - **Be careful with descendant selectors in recursive components!** For a CSS rule with the selector `.a .b`, if the element that matches `.a` contains a recursive child component, then all `.b` in that child component will be matched by the rule. ## CSS Modules A ` ``` The resulting classes are hashed to avoid collision, achieving the same effect of scoping the CSS to the current component only. Refer to the [CSS Modules spec](https://github.com/css-modules/css-modules) for more details such as [global exceptions](https://github.com/css-modules/css-modules#exceptions) and [composition](https://github.com/css-modules/css-modules#composition). ### Custom Inject Name You can customize the property key of the injected classes object by giving the `module` attribute a value: ```vue ``` ### Usage with Composition API The injected classes can be accessed in `setup()` and ` ``` The syntax works with [` ``` The actual value will be compiled into a hashed CSS custom property, so the CSS is still static. The custom property will be applied to the component's root element via inline styles and reactively updated if the source value changes.