Skip to content

Theme & Appearance

Mini Apps support automatic adaptation to the user's light/dark theme and provide rich theme color parameters and CSS variables.

ThemeParams

The ThemeParams object contains the color parameters of the client's current theme. Accessed via Telegram.WebApp.themeParams.

Color Properties

PropertyTypeDescription
bg_colorStringBackground color
text_colorStringPrimary text color
hint_colorStringHint text color
link_colorStringLink color
button_colorStringButton background color
button_text_colorStringButton text color
secondary_bg_colorStringSecondary background color
header_bg_colorStringHeader bar background color. Bot API 7.10+
bottom_bar_bg_colorStringBottom bar background color. Bot API 7.10+
accent_text_colorStringAccent text color. Bot API 7.10+
section_bg_colorStringSection background color. Bot API 7.10+
section_header_text_colorStringSection header text color. Bot API 7.10+
section_separator_colorStringSection separator color. Bot API 7.10+
subtitle_text_colorStringSubtitle text color. Bot API 7.10+
destructive_text_colorStringDestructive action text color. Bot API 7.10+

CSS Variables

The Mini App SDK automatically injects all theme colors as CSS variables, which can be used directly in stylesheets:

css
.my-element {
  background-color: var(--tg-theme-bg-color);
  color: var(--tg-theme-text-color);
}

.my-button {
  background-color: var(--tg-theme-button-color);
  color: var(--tg-theme-button-text-color);
}

.my-link {
  color: var(--tg-theme-link-color);
}

.my-hint {
  color: var(--tg-theme-hint-color);
}

Full CSS variable list:

CSS VariableCorresponding Property
--tg-theme-bg-colorbg_color
--tg-theme-text-colortext_color
--tg-theme-hint-colorhint_color
--tg-theme-link-colorlink_color
--tg-theme-button-colorbutton_color
--tg-theme-button-text-colorbutton_text_color
--tg-theme-secondary-bg-colorsecondary_bg_color
--tg-theme-header-bg-colorheader_bg_color
--tg-theme-bottom-bar-bg-colorbottom_bar_bg_color
--tg-theme-accent-text-coloraccent_text_color
--tg-theme-section-bg-colorsection_bg_color
--tg-theme-section-header-text-colorsection_header_text_color
--tg-theme-section-separator-colorsection_separator_color
--tg-theme-subtitle-text-colorsubtitle_text_color
--tg-theme-destructive-text-colordestructive_text_color

Listening for Theme Changes

javascript
Telegram.WebApp.onEvent('themeChanged', () => {
  const theme = Telegram.WebApp.themeParams;
  console.log('Background color:', theme.bg_color);
  console.log('Theme mode:', Telegram.WebApp.colorScheme);
});

SafeAreaInset

The SafeAreaInset object describes the device safe area insets (such as notch and rounded corner areas). Accessed via Telegram.WebApp.safeAreaInset. Bot API 8.0+

PropertyTypeDescription
topIntegerTop safe area inset in pixels
bottomIntegerBottom safe area inset in pixels
leftIntegerLeft safe area inset in pixels
rightIntegerRight safe area inset in pixels

Example

javascript
const inset = Telegram.WebApp.safeAreaInset;
document.body.style.paddingTop = inset.top + 'px';
document.body.style.paddingBottom = inset.bottom + 'px';

ContentSafeAreaInset

The ContentSafeAreaInset object describes the content safe area insets (excluding space occupied by the Mini App's own UI elements). Accessed via Telegram.WebApp.contentSafeAreaInset. Bot API 8.0+

PropertyTypeDescription
topIntegerTop content safe area inset in pixels
bottomIntegerBottom content safe area inset in pixels
leftIntegerLeft content safe area inset in pixels
rightIntegerRight content safe area inset in pixels

Example

javascript
const contentInset = Telegram.WebApp.contentSafeAreaInset;

// Combine with device safe area
const safeInset = Telegram.WebApp.safeAreaInset;
const totalTop = safeInset.top + contentInset.top;

document.querySelector('.content').style.paddingTop = totalTop + 'px';