@attribute in an HTML element

Attach a dictionary of attributes to the element.

Example

<h3 @attributes="Dictionary">Attribute</h3>

@code {
    Dictionary<string, object> Dictionary = new Dictionary<string, object>()
    {
        { "example","true" },
        { "score", 10 },
        { "object", new
            {
                Number = 100, 
                Text = "Test"
            }
        }
    };
}

Rendered HTML

<h3 example="true" score="10" object="{ Number = 100, Text = Test }">Attribute</h3>

@attribute in directive section

Set an attribute for a component.

Example

@attribute [Route("/attribute-in-directive-section")]

<h3>AttributeInDirectiveSection</h3>

Will equalize to

@page "/attribute-in-directive-section"

<h3>AttributeInDirectiveSection</h3>
BLAZOR SCHOOL
Designed and built with care by our dedicated team, with contributions from a supportive community. We strive to provide the best learning experience for our users.
Docs licensed CC-BY-SA-4.0
Copyright © 2021-2025 Blazor School
An unhandled error has occurred. Reload 🗙