CSS Encapsulation for Blazor Wasm

Viewed 261

Do Blazor components support css encapsulation like Angular? If so, how? Else, what is the recommended approach for css per component? I guess encapsulation can still be achieved manually but is there a better support from the framework itself?

2 Answers

It has been added to Blazor in .NET 5 with the name: CSS Isolation. You can apply CSS Isolation by naming a CSS file with the same as razor file.

for example, for MainLayout.razor it's MainLayout.razor.css

Note: you should place the CSS file in the same folder of the razor file.

It has some issues, for more details read this article.

Related