
CSS Isolation allows each Blazor component to have its own scoped stylesheet — styles that apply only to that component and won't leak out to affect other elements.
Create a CSS file with the same name as your component plus .css:
Counter.razorCounter.razor.cssBlazor automatically generates a unique attribute (like b-xyz123) and adds it to the component's HTML, then scopes the CSS selectors to match.
h1 {
color: purple;
font-size: 2rem;
}
button {
background-color: #512bd4;
color: white;
border-radius: 4px;
padding: 8px 16px;
}To style child components from a parent's scoped CSS, use the ::deep combinator:
::deep .child-element {
font-weight: bold;
}Non-isolated global styles go in wwwroot/css/app.css. Use scoped CSS for component-specific styles.
Reference:
TaskLoco™ — The Sticky Note GOAT