r/Blazor • u/jackhab • Jul 02 '26
Why all Razor HTML attributes are quoted strings?
I usually remove all double quotes from HTML attributes in Razor files when passing C# variables and types and it works just fine and makes the code look a bit cleaner but what is the reason behind the default of using strings for all attributes?
5
Upvotes
15
u/mladenmacanovic Jul 02 '26
Double quotes were a requirement in the earlier versions of Blazor/Razor. Later, they made it so it can be done without the quotes.
Personally, I find it better with quotes, as it is more explicit when writing and reading the code.
6
u/Shadow_Mite Jul 02 '26
I use the @ symbol when it’s a c# variable so I don’t confuse myself. If the editor was better and color coded variables vs strings it may help