Skip to main content

Fixed: Black Text on a Dark Background in a Teams Dialog

· 8 min read
Jagdish Kumawat
Founder @ Dewiride

In Teams' dark theme, the web page in my agent's dialog was almost invisible: black text on Teams' dark grey dialog. The page never set a text color, and its background is transparent, so Teams' dark dialog showed through behind the browser's default black text.

What I Was Doing​

An agent built with the Microsoft 365 Agents SDK opens a Teams dialog that shows a page it serves itself, wifi.html, with the guest Wi-Fi details. The page loads the Teams JavaScript library (TeamsJS) and connects to Teams with microsoftTeams.app.initialize(). Its style sets only the font and the spacing:

wwwroot/wifi.html (style)
body { margin: 0; padding: 0 24px; font-family: "Segoe UI", system-ui, sans-serif; font-size: 14px; }

In Teams' light theme, the page looked fine. Then I switched Teams on the web to the dark theme, as in How to Switch Microsoft Teams to Dark Theme, and opened the dialog again.

What I Expected​

The page's text readable on the dark dialog, like Teams' own text above it.

What I Got​

Teams' own title and app name were white, but the page's three lines were black on the dark grey dialog:

A Teams dialog titled Guest Wi-Fi from the app Dialog Page Demo in the dark theme: the app name and title are white, but the page's three lines, Network: Contoso-Guest, Password: ask at the front desk. It changes every day., and The guest network reaches the internet only., are black on the dark grey dialog and barely readable.

What I Checked​

The page's own colors. I read the computed text color and background color of the page's body, inside the dialog's frame, with getComputedStyle(document.body):

Output
color: rgb(0, 0, 0)
background-color: rgba(0, 0, 0, 0)
  • rgb(0, 0, 0) is black. The page sets no color, so this is the browser's default.
  • rgba(0, 0, 0, 0) is fully transparent. The page sets no background either, so whatever is behind the frame shows through: Teams' dialog, which Teams colors to match its theme.

In the light theme, the dialog behind the page is light, so black text reads well. In the dark theme, it's dark grey.

What Teams tells the page about its theme. TeamsJS gives a page its context with microsoftTeams.app.getContext(), and context.app.theme holds the theme's name. Microsoft's Get context for your tab describes it as the current user interface (UI) theme such as default, dark, or glass, contrast. The same context works in a dialog's page.

Why It Happens​

Teams changes its own colors for each theme, but it can't change the colors inside your page. A page that sets no text color gets the browser's black, and a page that sets no background lets Teams' dialog show through. In the dark theme, that's black text on a dark background.

The Fix​

Read the theme from TeamsJS, write it on the page's body, and give each theme a text color.

1. Style each theme. Give the page a dark text color by default, and white for the dark and high contrast themes:

wwwroot/wifi.html (style)
body { margin: 0; padding: 0 24px; font-family: "Segoe UI", system-ui, sans-serif; font-size: 14px; color: #242424; }
body[data-theme="dark"],
body[data-theme="contrast"] { color: #ffffff; }
  • color: #242424 is a dark grey for the light theme.
  • body[data-theme="dark"] matches the body only while it has the attribute data-theme="dark". The script below sets that attribute.
  • contrast is Teams' high contrast theme, which also has a black dialog, so it gets white text too.

2. Tell the page which theme Teams uses. After app.initialize(), read the theme and write it on the body:

wwwroot/wifi.html (script)
<script>
async function start() {
await microsoftTeams.app.initialize();

// Teams' theme: "default", "dark" or "contrast". The CSS above picks the text color from it.
const context = await microsoftTeams.app.getContext();
document.body.dataset.theme = context.app.theme;
}

start();
</script>
  • await microsoftTeams.app.initialize() connects the page to Teams first. getContext() comes after it.
  • context.app.theme is default, dark or contrast here.
  • document.body.dataset.theme = … sets the body's data-theme attribute, which the CSS rules above match.

Stop the agent with Ctrl+C and run dotnet run again, so it serves the new page. How to Match the Microsoft Teams Theme in a Web Page with TeamsJS builds this from an empty page and shows it in each theme.

After the Fix​

In the dark theme, the page now read dark, its body had data-theme="dark", and the text color was rgb(255, 255, 255), white:

The same Guest Wi-Fi dialog in the dark theme, now with the page's three lines in white and easy to read on the dark grey dialog.

In the high contrast theme, the same rules gave white text on Teams' black dialog. In the light theme, the page reads default, neither rule matches, and the text stays dark grey on the light dialog.

Common Mistakes​

MistakeWhat happensDo this instead
Setting color: #ffffff for every themeThe text disappears on the light theme's light dialogSet the color for each theme
Styling only darkHigh contrast also has a black dialog, and the text stays dark thereStyle contrast too
Checking the page only in the light themeThe problem shows only in the dark and high contrast themesSwitch Teams to Dark and open the dialog again

Troubleshooting​

SymptomLikely causeFix
Black or dark text on a dark dialogThe page has no text color for dark themesRead context.app.theme and style dark and contrast
The body never gets a data-theme attributeThe script stopped before setting it, for example because TeamsJS didn't loadCheck the browser console for errors
The page still looks the same after the changeThe agent still serves the old pageRestart the agent
The page's text is still dark in Dark, though it follows a themeThe page takes the theme from the agent's task/fetch request, which said default in Teams on the webRead the theme in the page with app.getContext(), as in Fixed: "theme": "default" in a Teams task/fetch Request While Teams Is in Dark Theme

FAQ​

Which theme values can a page get?​

Microsoft's docs list default, dark and contrast, plus glass for Teams on Apple Vision Pro, and say that default means the light theme. In Teams on the web, I got default while Teams followed my computer's light theme, dark in Dark and contrast in High contrast.

Why is the page's background transparent?​

A page that sets no background color has a transparent one. Teams shows the dialog's page in a frame on top of the dialog, so the dialog's own color shows through it.

Conclusion​

Black text on a dark background in a Teams dialog means the page uses the browser's default text color while Teams' dark dialog shows through its transparent background. Read context.app.theme with TeamsJS after app.initialize(), write it on the body as data-theme, and give dark and contrast a light text color.

Additional Resources​