Sub topic 11
Debugging a hook that has no effect
This chapter assumes you can apply a component hook in a Lightning web component's CSS file and that you know how custom properties inherit. It also assumes you can open browser developer tools.
A styling hook that does nothing fails silently. The browser doesn't warn about an unknown custom property. It stores the value and nothing reads it. Debugging means finding out which of four things went wrong: the name, the place, the cascade, or the value.
Start with the name
The component only reads the exact hook names it supports. A misspelled or invented name is valid CSS and has no effect.
.brand-action {
--slds-c-button-brand-color-backgroud: #5a1ba9;
--slds-c-button-color-background: #5a1ba9;
}Neither line styles a brand button. The first misspells background. The second is a real hook name, but for the base (neutral) button, so a brand variant ignores it. The variant is part of the hook name. Check the name against the component's styling hooks documentation, or copy it from the inner element, as shown below.
Check where the hook is set
Custom properties inherit downward. Set the hook on the host element or on an ancestor of it. A hook set on a sibling or on a descendant of the host never reaches the inner button.
<template>
<div class="actions">
<lightning-button class="brand-action" variant="brand" label="Save"></lightning-button>
</div>
</template>.actions {
--slds-c-button-brand-color-background: #5a1ba9;
}This works because .actions is an ancestor of the button. A rule such as .brand-action lightning-button would not, because it targets an element that doesn't exist inside the host.
Inspect it in developer tools
The most reliable method is to read what the component actually asks for.
- Select the
lightning-buttonelement in the Elements panel and look in the Styles pane for your declaration. - If the declaration is missing, your selector didn't match. Fix the selector or the class name.
- If it's there but struck through, another rule with higher specificity or later order overrides it.
- Expand the element's shadow root and select the inner
button. Find itsbackground-colorrule. It readsvar(--slds-c-button-brand-color-background, ...), and the name insidevar()is the hook the component honors. - In the Computed pane, filter by
--slds-c-button. This confirms which value reached the element.
Cascade and value problems
Two rules at equal specificity are resolved by order, and the later one wins. The earlier example from the scoping chapter works the same way. A region rule such as .compact-region .brand-action beats a plain .brand-action rule because its selector is more specific. If an instance keeps an unexpected value, look for a more specific selector that sets the same hook.
A value problem is subtler. A custom property accepts any text. If you write --slds-c-button-radius-border: big;, the declaration is kept, but the property that uses it becomes invalid when the browser computes it, so the component falls back to its default. Use a value the underlying property accepts, such as a color, a length like 1rem, or a keyword.
.brand-action {
--slds-c-button-radius-border: 1rem;
}If every check passes and nothing changes, the component probably doesn't expose a hook for that style. Use another approach, such as a utility class or custom CSS where the component allows it.
Exercise
A brand lightning-button keeps its default blue background. Your CSS sets --slds-c-button-color-background: #5a1ba9; on the button's class. The declaration shows in the Styles pane and isn't struck through. What is the most likely cause, and how do you confirm it?
Show answer
The hook name is for the base button, not the brand variant, so the brand button never reads it. Expand the shadow root, select the inner button, and read the name inside var() in its background-color rule. It will be --slds-c-button-brand-color-background. Use that name.