Fixed: Black Text on a Dark Background in a Teams Dialog
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:
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:

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):
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:
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: #242424is a dark grey for the light theme.body[data-theme="dark"]matches thebodyonly while it has the attributedata-theme="dark". The script below sets that attribute.contrastis 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:
<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.themeisdefault,darkorcontrasthere.document.body.dataset.theme = …sets thebody'sdata-themeattribute, 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:

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
| Mistake | What happens | Do this instead |
|---|---|---|
Setting color: #ffffff for every theme | The text disappears on the light theme's light dialog | Set the color for each theme |
Styling only dark | High contrast also has a black dialog, and the text stays dark there | Style contrast too |
| Checking the page only in the light theme | The problem shows only in the dark and high contrast themes | Switch Teams to Dark and open the dialog again |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Black or dark text on a dark dialog | The page has no text color for dark themes | Read context.app.theme and style dark and contrast |
The body never gets a data-theme attribute | The script stopped before setting it, for example because TeamsJS didn't load | Check the browser console for errors |
| The page still looks the same after the change | The agent still serves the old page | Restart the agent |
| The page's text is still dark in Dark, though it follows a theme | The page takes the theme from the agent's task/fetch request, which said default in Teams on the web | Read 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
- Get context for your tab, on Microsoft Learn.
- app module of TeamsJS, on Microsoft Learn.
- HTMLElement: dataset property, on MDN.
