Skip to content

UI Components

Mini Apps provide multiple native UI components accessible through the Telegram.WebApp object.

BackButton

The back button, displayed on the left side of the Mini App header bar.

Properties

PropertyTypeDescription
isVisibleBooleanWhether the back button is currently visible

Methods

MethodDescription
show()Show the back button
hide()Hide the back button
onClick(callback)Register a click event callback
offClick(callback)Remove a click event callback

Example

javascript
const backButton = Telegram.WebApp.BackButton;

backButton.show();
backButton.onClick(() => {
  // Handle back navigation
  window.history.back();
});

BottomButton

Bottom button component, including the main button (MainButton) and secondary button (SecondaryButton).

MainButton is a full-width button at the bottom of the Mini App, commonly used for submit or confirm actions. SecondaryButton was introduced in Bot API 7.10+.

Properties

PropertyTypeDescription
typeStringButton type: "main" or "secondary"
textStringText displayed on the button (max 64 characters)
colorStringButton background color
textColorStringButton text color
isVisibleBooleanWhether the button is visible
isActiveBooleanWhether the button is clickable
hasShineEffectBooleanWhether the button displays a shine effect. Bot API 7.10+
positionStringButton position: "left", "right", "top", "bottom". Bot API 7.10+
isProgressVisibleBooleanWhether a loading progress indicator is shown

Methods

MethodDescription
setText(text)Set the button text
show()Show the button
hide()Hide the button
enable()Enable the button
disable()Disable the button
showProgress(leaveActive)Show loading progress. When leaveActive is true, the button remains clickable
hideProgress()Hide loading progress
setParams(params)Set button parameters in batch
onClick(callback)Register a click event callback
offClick(callback)Remove a click event callback

setParams

javascript
Telegram.WebApp.MainButton.setParams({
  text: 'Submit',
  color: '#2481cc',
  text_color: '#ffffff',
  has_shine_effect: true,
  is_active: true,
  is_visible: true
})
ParameterTypeRequiredDescription
textStringNoButton text
colorStringNoButton background color
text_colorStringNoText color
has_shine_effectBooleanNoWhether to show shine effect
positionStringNoButton position (SecondaryButton only)
is_activeBooleanNoWhether clickable
is_visibleBooleanNoWhether visible

Example

javascript
const mainButton = Telegram.WebApp.MainButton;

mainButton.setText('Confirm Payment');
mainButton.color = '#31b545';
mainButton.textColor = '#ffffff';

mainButton.onClick(() => {
  mainButton.showProgress();
  // Handle payment logic...
  setTimeout(() => {
    mainButton.hideProgress();
  }, 2000);
});

mainButton.show();

SettingsButton

Settings button displayed in the Mini App's more menu. Bot API 7.0+

Properties

PropertyTypeDescription
isVisibleBooleanWhether the settings button is visible

Methods

MethodDescription
show()Show the settings button
hide()Hide the settings button
onClick(callback)Register a click event callback
offClick(callback)Remove a click event callback

Example

javascript
const settingsButton = Telegram.WebApp.SettingsButton;

settingsButton.show();
settingsButton.onClick(() => {
  // Navigate to settings
  navigateTo('/settings');
});

HapticFeedback

Haptic feedback controller providing three types of vibration feedback.

Methods

impactOccurred

javascript
Telegram.WebApp.HapticFeedback.impactOccurred(style)

Triggers impact-type haptic feedback.

ParameterTypeRequiredDescription
styleStringYesImpact intensity: "light", "medium", "heavy", "rigid", "soft"

notificationOccurred

javascript
Telegram.WebApp.HapticFeedback.notificationOccurred(type)

Triggers notification-type haptic feedback.

ParameterTypeRequiredDescription
typeStringYesNotification type: "error", "success", "warning"

selectionChanged

javascript
Telegram.WebApp.HapticFeedback.selectionChanged()

Triggers selection-change haptic feedback, typically used when the user changes a selection.

Example

javascript
const haptic = Telegram.WebApp.HapticFeedback;

// Button click feedback
document.getElementById('btn').addEventListener('click', () => {
  haptic.impactOccurred('medium');
});

// Success feedback
function onSuccess() {
  haptic.notificationOccurred('success');
}

// Selection change feedback
document.querySelectorAll('.option').forEach(el => {
  el.addEventListener('click', () => {
    haptic.selectionChanged();
  });
});