Radzen Blazor Components

Blazor ThemeService

Change the theme of your application at runtime with dynamic theme switching.

Console log

Persist the theme Link to this section

The Radzen.Blazor library provides a built-in service that persists the current theme in a cookie. This means that the theme will be remembered even after the user closes the browser or navigates to a different page. The theme will be restored when the user returns to the application.

1. Open Program.cs file(s) and register the CookieThemeService:


builder.Services.AddRadzenCookieThemeService(options =>
{
    options.Name = "MyApplicationTheme"; // The name of the cookie
    options.Duration = TimeSpan.FromDays(365); // The duration of the cookie
});

2. Open MainLayout.razor and inject the CookieThemeService:

@inject CookieThemeService CookieThemeService

3. Open the App.razor file of your application and add this code:

@code {
    [CascadingParameter]
    private HttpContext HttpContext { get; set; }

    [Inject]
    private ThemeService ThemeService { get; set; }
    
    [Inject]
    private IOptions<CookieThemeServiceOptions> Options { get; set; }

    protected override void OnInitialized()
    {
        base.OnInitialized();

        if (HttpContext != null)
        {
            var theme = HttpContext.Request.Cookies["MyApplicationTheme"];

            if (!string.IsNullOrEmpty(theme))
            {
                ThemeService.SetTheme(theme, false);
            }
            else
            {
                HttpContext.Response.Cookies.Append("MyApplicationTheme", "material" , new CookieOptions { Secure = Options.Value.IsSecure, Expires = DateTimeOffset.Now.Add(Options.Value.Duration) });    
            }
        }
    }
}

Changing themes at runtime in Radzen Blazor Studio Link to this section

Use Radzen ThemeService and a RadzenDropDown to change the app’s theme at runtime.

Radzen Blazor Newsletter

Get an email when new components and releases ship.

All the tools in one place

Save Hours on Every Project

With Radzen Blazor subscription you get the full toolkit, including:

Dedicated support backed by proven expertise

Premium themes and theme editor

Ready-to-use UI blocks

Complete app templates

Visual design-time-experience

Radzen Blazor Studio

Radzen Blazor Components, © 2018-2026 Radzen.
Source Code licensed under MIT

Demos Configuration

Premium Themes

  • Material 3
  • Material 3 Dark
  • Material 3 Expressive
  • Material 3 Expressive Dark
  • Fluent
  • Fluent Dark

Free Themes

  • Material
  • Material Dark
  • Standard
  • Standard Dark
  • Default
  • Dark
  • Humanistic
  • Humanistic Dark
  • Software
  • Software Dark
An error has occurred. This app may no longer respond until reloaded. Reload 🗙