Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,27 @@ body[data-theme="dark"] {
}
```

## Flash effect (optional)

When using the dark theme, you may notice a brief white "flash" before the page fully renders.
This occurs because the browser's default background color is white, and the FluentUI styles may not load instantly—especially on slower network connections.

To prevent this flash, add the following CSS to your `index.html`, `App.razor`, or `_layout.cshtml` file (in the `<head>...</head>` HTML section).
This sets a dark background color immediately, before the FluentUI styles are applied.

```html
<style>
@media (prefers-color-scheme: dark) {
body {
background-color: #292929;
color: #ffffff;
}
}
</style>
```

**Notes:** In Razor/CSHTML files, escape the `@` symbol by doubling it: use `@@media` instead of `@media`.

## themeChanged event

A JavaScript `themeChanged` event is triggered each time the `data-theme` attribute changes.
Expand Down
13 changes: 13 additions & 0 deletions examples/Demo/FluentUI.Demo.Client/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@
<base href="/" />
<link rel="stylesheet" href="app.css" />
<link rel="stylesheet" href="FluentUI.Demo.Client.styles.css" />
<style>
/* Set the default dark mode styles,
used before the Fluent UI theme switcher is initialized
This is to avoid a flash of white when in dark mode.
Update as needed to match your dark theme.
*/
@media (prefers-color-scheme: dark) {
body {
background-color: #292929;
color: #ffffff;
}
}
</style>
</head>

<body>
Expand Down
14 changes: 14 additions & 0 deletions examples/Demo/FluentUI.Demo/Components/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@
<link rel="stylesheet" href="FluentUI.Demo.styles.css" />
<link rel="icon" type="image/x-icon" href="favicon.ico" />
<HeadOutlet @rendermode="@DemoRenderMode" />

<style>
/* Set the default dark mode styles,
used before the Fluent UI theme switcher is initialized
This is to avoid a flash of white when in dark mode.
Update as needed to match your dark theme.
*/
@@media (prefers-color-scheme: dark) {
body {
background-color: #292929;
color: #ffffff;
}
}
</style>
</head>

<body use-reboot="@reboot">
Expand Down
Loading