Salesforce Dictionary - Free Salesforce GlossarySalesforce Dictionary
Full Cascading Style Sheet (CSS) entry
How-to guide

How to write CSS for Salesforce

CSS in Salesforce is most useful when it composes with SLDS and respects component scoping. Bespoke CSS is the exception, not the rule.

By Dipojjal Chakrabarti · Founder & Editor, Salesforce DictionaryLast updated May 19, 2026

CSS in Salesforce is most useful when it composes with SLDS and respects component scoping. Bespoke CSS is the exception, not the rule.

  1. Start with SLDS classes

    Compose Lightning Web Components from SLDS utility classes (slds-grid, slds-text-heading_medium). Custom CSS only fills the gaps SLDS does not cover.

  2. Scope CSS to the component

    Write CSS in the component's own stylesheet file. Avoid global selectors; LWS scoping enforces component boundaries.

  3. Use design tokens for theme values

    Reference SLDS design tokens (var(--lwc-colorBrand)) rather than hard-coded colours. Tokens propagate theme changes automatically.

  4. For Experience Cloud, use Branding Sets first

    Configure Branding Sets in Experience Builder. Add Site CSS only when Branding Sets cannot cover the design need.

  5. Test across surfaces

    LWC, Aura, Visualforce, Email Templates, Experience Cloud each render CSS differently. Test the styling in every surface it ships to before launch.

Gotchas
  • Custom CSS overriding SLDS produces accessibility regressions and breaks on Salesforce releases. Compose with SLDS, do not fight it.
  • LWC enforces shadow DOM scoping. Selectors that reach across components fail; communicate through CSS custom properties or slots.
  • Email Template CSS needs to be inlined for cross-client compatibility. Internal style elements do not render reliably in Outlook.
  • Experience Cloud Site CSS overrides Branding Sets. Mixing both creates inconsistent theming; pick one as the primary source.

See the full Cascading Style Sheet (CSS) entry

Cascading Style Sheet (CSS) includes the definition, worked example, deep dive, related terms, and a quiz.