Component Parameters
Parameters are how parent components configure their children — the Blazor equivalent of props in React.
On this page · 5 min · Beginner
On this page
- Learning objectives
- Explanation
- Code example
- Step by step
- Real-world use
- Common mistakes
- Best practices
- Remember this
- Practice exercise
- Mini quiz
- Related topics
- My notes
- Reading time
- 5 min
- Difficulty
- Beginner
- Updated
- Oct 29, 2026
Related tutorials
Interview questions
Learning objectives#
- Declare and pass parameters
- Accept child content with RenderFragment
- Use cascading parameters for shared values
- Read route and query-string values
Explanation#
Mark a public property with [Parameter]. The parent sets it as an attribute: <Alert Type="warning" />.
A RenderFragment parameter named ChildContent receives the markup between the component’s tags.
Cascading values flow to all descendants without passing them at every level — useful for themes or the current user.
[SupplyParameterFromQuery] binds a query-string value such as ?page=2 to a property on a routable component.
Code example: An alert with child content#
<div class="alert alert-@Type" role="alert">
@if (Title is not null) { <strong>@Title</strong> }
@ChildContent
</div>
@code {
[Parameter] public string Type { get; set; } = "info";
[Parameter] public string? Title { get; set; }
[Parameter] public RenderFragment? ChildContent { get; set; }
}
@* Usage in a page *@
@* <Alert Type="warning" Title="Heads up!">Stock is low for <em>Laptop</em>.</Alert> *@
Renders <div class="alert alert-warning"> with a bold “Heads up!” followed by “Stock is low for Laptop.”
This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.
Step-by-step explanation#
- Type and Title are simple parameters set as attributes.
- Anything between <Alert> and </Alert> becomes ChildContent.
- @ChildContent renders that markup inside the alert.
- Default values apply when the parent omits a parameter.
Real-world use case#
A design-system Card, Modal or Alert component that wraps any content while keeping consistent styling.
Common mistakes#
The parent overwrites it on its next render. Copy it to a private field, or raise an EventCallback to ask the parent to change it.
New object instances cause unnecessary re-renders. Pass stable instances or simple values.
Best practices#
- Treat parameters as read-only inputs
- Use RenderFragment for flexible layouts
- Use cascading values sparingly
- Give parameters sensible defaults
Remember this#
[Parameter] = input from the parent.
ChildContent = markup between the tags.
Never modify a parameter inside the child.
Practice exercise#
Your task: Read the page number from /products?page=3 into a property.
Show solution
@page "/products"
@code {
[SupplyParameterFromQuery] public int? Page { get; set; }
}
Mini quiz#
What must a parameter be called to receive markup between the component’s tags?
Want more? Practise all Blazor MCQs · Blazor interview questions
My notes#
Saved in this browser.