# Theming and dark mode

> Match in-app messages to your app's colors, fonts, corner radius and spacing, control dark mode, and understand how per-message styles override the theme.

The default message views take their look from a `HeraldTheme`: light and dark colors, fonts, corner radius and spacing. It is the same theme type the content card feed uses, so one definition styles both.

## Before you start

- You install the default presenter with `Herald.useDefaultInAppUI` (iOS) or `HeraldInAppPresenter.install` (Android).

## 1. Pass your theme to the presenter

:::tabs
::tab ios
```swift
import SwiftUI
import HeraldUI

var light = HeraldColors.light
light.accent = Color(red: 0.07, green: 0.55, blue: 0.42)
var dark = HeraldColors.dark
dark.accent = Color(red: 0.36, green: 0.84, blue: 0.67)

let theme = HeraldTheme(lightColors: light, darkColors: dark, cornerRadius: 16, spacing: 20)
Herald.useDefaultInAppUI(theme: theme)
```
::tab android
```kotlin
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.herald.ui.HeraldColors
import com.herald.ui.HeraldInAppPresenter
import com.herald.ui.HeraldTheme

val theme = HeraldTheme(
    lightColors = HeraldColors.Light.copy(accent = Color(0xFF128C6B)),
    darkColors = HeraldColors.Dark.copy(accent = Color(0xFF5CD6AB)),
    cornerRadius = 16.dp,
    spacing = 20.dp,
)
HeraldInAppPresenter.install(theme)
```
:::

Both calls return the presenter. Its `theme` property can be changed later, for example when the user picks a different app theme; the next message uses the new value.

## What the theme controls

| Theme value | Used in messages for |
|---|---|
| `surface` | Message background (all four types) |
| `onSurface` | Header, body, the close button, and the text of secondary buttons |
| `accent` | Background of the first (primary) button |
| `onAccent` | Text of the primary button |
| `scrim` | The dimmed layer behind a modal |
| `outline` | Image placeholder while an image loads |
| `typography.title`, `.body`, `.button` | Header, body and button text |
| `cornerRadius` | Message and button corners |
| `spacing` | Padding inside messages and the slideup's distance from the screen edge |

Buttons after the first have no fill: they use the text color on the message background.

## Per-message styles

A message can carry its own `style`: `backgroundColor`, `textColor`, `buttonColor`, `buttonTextColor` and `cornerRadius`. Each field that is set replaces the matching theme value for that message only. Fields left null, and colors that are not valid `#RRGGBB` or `#AARRGGBB` hex, fall back to the theme, with one exception: when a message sets `backgroundColor` without `textColor`, the text is black or white, whichever has the higher contrast against that background. `buttonColor` without `buttonTextColor` works the same way for the button label. The theme's text colors are picked for the theme's own surfaces, so they could be unreadable on a color the message chose.

| Style field | Replaces |
|---|---|
| `backgroundColor` | `surface` |
| `textColor` | `onSurface` |
| `buttonColor` | `accent` |
| `buttonTextColor` | `onAccent` |
| `cornerRadius` | `cornerRadius` |

**Message colors do not change with dark mode.** A message with a white `backgroundColor` stays white in dark mode. To keep dark mode working, leave colors null and let the theme decide, or pick colors that read well in both modes.

## Dark mode

| `darkMode` | Behavior |
|---|---|
| `nil` / `null` (default) | Follows the system light or dark setting |
| `true` | Always uses `darkColors` |
| `false` | Always uses `lightColors` |

If your app has its own appearance setting, set `darkMode` from it and update `presenter.theme` when the user changes it. On iOS, a forced value also sets the message window's interface style, so system controls inside the message match.

## Fonts

:::tabs
::tab ios
```swift
let typography = HeraldTypography(
    title: .custom("Avenir Next", size: 20, relativeTo: .title3).weight(.semibold),
    body: .custom("Avenir Next", size: 16, relativeTo: .body)
)
Herald.useDefaultInAppUI(theme: HeraldTheme(typography: typography))
```
::tab android
```kotlin
val typography = HeraldTypography(
    title = TextStyle(fontFamily = AvenirNext, fontSize = 20.sp, fontWeight = FontWeight.SemiBold),
    body = TextStyle(fontFamily = AvenirNext, fontSize = 16.sp),
)
HeraldInAppPresenter.install(HeraldTheme(typography = typography))
```
:::

The defaults are system text styles on iOS and `sp` sizes on Android, so they follow the user's text size. Keep that when you replace them: `relativeTo:` on iOS, `sp` on Android.

## HTML messages

The theme does not style an HTML page. The message background (the theme's `surface`, or the message's `backgroundColor`) shows behind and around the page. Style the page with its own CSS, including dark mode, and test it in both modes on both platforms.

## Verify it works

Show a modal in light mode and in dark mode, and once with the system text size at its largest. Use `Herald.shared.debugShowInAppMessage(_:)` / `Herald.debugShowInAppMessage(_:)` with a message loaded through `debugLoadMessages` to repeat this without waiting for a trigger; both are for debug builds only.

## Troubleshooting

- **Messages ignore the feed theme.** The feed reads the theme from the view tree; the presenter does not. Pass the theme to `useDefaultInAppUI` or `install` as well.
- **One message looks off-brand.** It carries its own `style` colors. Check the message, not the theme.
- **Text is clipped at large text sizes.** A custom font with a fixed size. Use `relativeTo:` or `sp`.

## Next

- [Custom views](/docs/in-app-messages/custom-views)
- [Accessibility](/docs/in-app-messages/accessibility)
