Applying SLDS
The Salesforce Lightning Design System (SLDS) is a CSS framework with thousands of artifacts. This skill teaches agents how to find and correctly use them.
Version: This skill targets SLDS v2. Legacy
--lwc-*tokens andslds-*--modifiersyntax are deprecated.Audit scope: The companion
design-systems-slds-validateskill analyzer only scans.css,.html, and.jsfiles. Use it directly for LWC and similar HTML/CSS/JS components; treat it as a partial signal for JSX/TSX or other framework-specific template formats and supplement with manual review.
What is SLDS?
Scope
This skill covers:
- Which blueprint to use for a given UI pattern
- How to style with hooks (color, spacing, typography, shadows, borders)
- Which utility classes to use for layout, spacing, visibility
- Which icon to use and from which category
- SLDS naming conventions, class structure, hook syntax
This skill includes basic accessibility reminders (icon alt text, focus outlines, color-not-sole-indicator) in the validation checklists. Full WCAG compliance requires a dedicated accessibility review.
This skill does NOT cover (use companion skills):
- Design decisions -- visual hierarchy, composition, interaction patterns
- LWC mechanics -- component structure, @wire, @api, lifecycle, events (not yet available)
- Full accessibility -- WCAG conformance, ARIA patterns, keyboard navigation, focus management, contrast ratios (not yet available)
Component Selection Hierarchy
Always follow this order:
If building in LWC, check for an LBC first: Lightning Component Library
If no LBC exists (or not using LWC), select an SLDS Blueprint. See references/component-selection.md [blocked].
Core Rules
Do
- Follow the selection hierarchy: LBC > Blueprint > Hooks > Custom CSS
- Use
var(--slds-g-*, fallback)for all themeable values - Create custom classes (
my-*,c-*) instead of overriding.slds-* - Verify every hook, class, and utility exists before using it — run the search scripts; never assume an artifact exists based on naming patterns (see Verify Before You Use)
- Pair surface colors with on-surface colors for text
- Provide
alternative-texton every<lightning-icon>
Don't
- Hard-code colors, spacing, or typography values
- Override
.slds-*classes directly - Use deprecated
--lwc-*tokens as primary values - Use
--slds-s-*(shared) hooks -- they are private/internal - Reassign hook values -- only reference them with
var() - Use color alone to convey meaning
- Invent hook names by interpolating patterns from other families (see Naming Traps below)
Hook Naming Traps
SLDS hook families do NOT all follow the same naming pattern. Agents frequently invent hooks that don't exist by assuming {prefix}-{number} works universally. Always verify a hook exists via the bundled search-hooks.cjs script or assets/hooks-index.json before using it.
Trap 1: Font size hooks are NOT numbered
Rule: For font sizes, use --slds-g-font-size-base (the one base size) or --slds-g-font-scale-* (the numbered scale). Never --slds-g-font-size-N.
Trap 2: Color hooks always require a number
Rule: Every --slds-g-color-* hook ends in a number. Pick by emphasis: -1 (low), -2 (medium), -3 (high).
Trap 3: Not all values have hook equivalents
Some CSS values (e.g., min-width: 7rem for label alignment) have no SLDS hook. This is acceptable:
Rule: When no hook exists, use the value directly with a comment explaining it's intentional. Prefer SLDS grid utilities (slds-size_*) as alternatives to hardcoded widths where possible.
Verify Before You Use
Rule: Never include an SLDS hook, utility class, blueprint class, or icon in generated code without first confirming it exists in the metadata. Guessing based on naming patterns is the primary source of invented artifacts.
Run the appropriate search command before emitting any SLDS artifact:
If the search returns no match: do not use the artifact. Find an alternative from the search results or build custom with verified hooks.
Naming Conventions
Use a consistent prefix for custom classes to avoid collision with SLDS:
Avoid: generic names (container, wrapper), SLDS-like names (custom-slds-button), BEM on SLDS classes (slds-card__custom-header).
Custom hook namespacing:
Knowledge Map
This skill bundles comprehensive SLDS knowledge. Read files as needed -- don't read everything upfront.
Decision Guides (start here for each task)
Search Scripts (find specific artifacts)
Deep-Dive Guidance (read for detailed rules)
Raw Metadata (structured data for lookup)
Do not read metadata JSON files directly — they are too large for agent context (hooks-index.json is 6,000+ lines; icon-metadata.json is 38,000+ lines). Use the search scripts above to query them.
Authoring Workflow
Phase 1: Understand the Need
Identify:
- What UI pattern is needed? (form, table, modal, card, etc.)
- What framework? (LWC, React, Vue, Angular, vanilla)
- What data will it display?
- What states does it need? (loading, empty, error, success)
Phase 2: Select the Artifact
- If LWC: Check the Lightning Component Library for an LBC
- Search blueprints:
node scripts/search-blueprints.cjs --search "<pattern>" - Read the blueprint YAML:
assets/blueprints/components/<name>.yamlfor exact classes, modifiers, states, and accessibility requirements - No match? Build custom with hooks (see Phase 3)
Details: references/component-selection.md [blocked]
Phase 3: Apply Styling
- Read: references/styling-decision-guide.md [blocked]
- Colors: Classify role (surface, accent, feedback, border) then pick hook
- Spacing: Use utility classes (
slds-p-*,slds-m-*) or hooks (--slds-g-spacing-*) - Layout: Use grid utilities (
slds-grid,slds-col,slds-size_*) - Custom CSS: Use
var(--slds-g-*, fallback), custom class prefixes only
Phase 4: Add Icons
- Read: references/icons-decision-guide.md [blocked]
- Search:
node scripts/search-icons.cjs --query "<description>" - In LWC: Use
<lightning-icon>withalternative-text - In non-LWC: Use SVG with
slds-iconclasses andslds-assistive-text
Phase 5: Validate (Mandatory — Do Not Skip)
Step 1: Run the SLDS linter. This is required. Zero violations is the target.
The linter catches hardcoded values, class overrides, and deprecated tokens. Fix all violations before proceeding. Do not rationalize violations as acceptable.
Step 2: Verify no invented hooks. Confirm every --slds-g-* hook in the output exists in assets/hooks-index.json. Cross-reference against the T051 check in checklists.md [blocked].
Step 3: Run through checklists.md [blocked] for the checks the linter cannot automate:
- All
var(--slds-g-*)have fallback values (T002) - Surface/accent/feedback color hooks are properly paired (T010–T013)
- Spacing uses hooks or utility classes — no magic
pxvalues (T020–T021) - Font sizes use
--slds-g-font-scale-*, not--slds-g-font-size-N(T031) - All icons have accessibility text (A004)
- Custom classes use
my-*orc-*prefix (Q010)
Step 4 (optional): Run the full quality audit using the design-systems-slds-validate skill for a scored report before code review or deployment. Use it directly for LWC / HTML-CSS-JS components; for JSX/TSX outputs, treat the result as partial coverage only. Target a B grade (≥80) or higher before marking work complete.
Quick Reference
Common Hook Patterns
Common Utility Patterns
Examples
See examples.md [blocked] for worked examples demonstrating the full workflow from intent to SLDS artifact selection.
Validation
See checklists.md [blocked] for validation checklists aligned with the design-systems-slds-validate skill.
