A component’s own stylesheet
Name a sheet .scoped.css and its selectors reach only the elements that component declares.
Goal
Give the item component a stylesheet of its own, and see that the page links it only because that component rendered — and that its selectors cannot reach anything else.
A stylesheet beside a fragment, named for it, belongs to it. There is no build step to configure and no class-name mangling to read in a devtools pane: the compiler knows which elements that template declares, so it can scope the selectors to exactly those.
1 · Write the sheet
/* app/fragments/item.scoped.css */
li {
display: flex;
gap: 8px;
padding: 6px 0;
}
.price {
margin-inline-start: auto;
font-variant-numeric: tabular-nums;
}Bare li, and it is safe: the selector is rewritten to reach the li this template declares and nothing else. A sibling fragment with its own li is untouched, and so is one this component happens to contain.
2 · Check what the page linked
$ weft why / css layout.css · styles.css · fragments/item.scoped.css note item.scoped.css is linked because fragments/item rendered
A page links the stylesheets of the components on it, and not the application’s whole design system. Remove the component and the link goes with it, because the link was never a line anybody wrote — see a component’s own stylesheet.