Lightning Web Components use standard CSS for styling, with built-in Shadow DOM encapsulation that scopes styles to each component.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/trailheadapps/lwc-recipes/llms.txt
Use this file to discover all available pages before exploring further.
CSS File Structure
Each component can have its own CSS file that shares the component’s name:Shadow DOM Scoping
Styles defined in a component’s CSS file are automatically scoped to that component using Shadow DOM. This means:- Styles don’t leak out to parent components
- External styles don’t affect the component (except inherited properties)
- Each component has its own isolated styling context
lwc/contactTile/contactTile.css:1
img selector only affects images inside the contactTile component, not images elsewhere in the application.
The :host Selector
Use the:host pseudo-class to style the component’s host element itself:
- Set the display mode of the component
- Define CSS custom properties for child components
- Apply default spacing or layout
SLDS Design Tokens
Lightning Web Components have access to Salesforce Lightning Design System (SLDS) design tokens through CSS custom properties: Example:lwc/eventSimple/eventSimple.css:2
--slds-g-color-*- Color tokens--slds-g-sizing-*- Sizing and spacing tokens--slds-g-font-*- Typography tokens--slds-g-radius-*- Border radius tokens
Multiple Stylesheets
You can import additional CSS files using the staticstylesheets property:
Example: lwc/stylesheets/stylesheets.js:1
lwc/stylesheets/stylesheets.css:1
lwc/stylesheets/text-styles.css:1
Styling Base Components
You can style Lightning base components using class names:Best Practices
- Use SLDS utility classes in templates:
class="slds-var-m-around_medium" - Leverage SLDS design tokens for consistent styling
- Keep component styles focused and minimal
- Use
:hostfor component-level layout - Avoid
!important- Shadow DOM scoping makes it unnecessary - Use semantic class names that describe purpose, not appearance
