menumenu_openMDC

Banner

descriptionREADMEwidgetsDemo

A Material Design banner displays an important, succinct message in-flow (typically below a top app bar) and provides 1–2 actions for users to address or dismiss it. Unlike a snackbar, a banner is persistent and pushes page content rather than floating over it.

Basic Usage

<mdc-banner
    icon="wifi_off"
    primary-action="Turn on Wi-Fi"
    secondary-action="Dismiss"
    dismiss-on-action
>
    Your device is currently offline. Some features may be unavailable.
</mdc-banner>

Properties

Property Attribute Type Default Description
open open boolean true Controls whether the banner is expanded and visible in layout flow.
variant variant 'surface' | 'surface-container' | 'primary-container' | 'secondary-container' | 'tertiary-container' | 'error-container' | 'inverse-surface' 'surface' Color variant of the banner.
layout layout 'auto' | 'single-line' | 'stacked' 'auto' Arrangement of message and action buttons.
headline headline string '' Optional short headline above the message.
supportingText supporting-text string '' Optional supporting text (alternative to default slot).
icon icon string '' Optional leading Material Symbol icon name.
iconContainer icon-container boolean false Wraps the leading icon in a 40px circular tinted container.
primaryAction primary-action string '' Optional label for the built-in primary text action button.
secondaryAction secondary-action string '' Optional label for the built-in secondary text action button.
noDivider no-divider boolean false Hides the 1px bottom hairline divider.
dismissOnAction dismiss-on-action boolean false Closes the banner automatically when a built-in action is clicked (unless prevented).
quick quick boolean false Skips open/close expand-collapse animations.

Slots

  • (default): Banner message / supporting text.
  • icon: Custom leading icon or illustration.
  • headline: Custom headline content above the message.
  • primary-action: Custom primary action control (e.g. <mdc-button>).
  • secondary-action: Custom secondary action control.
  • actions: Arbitrary custom action controls.

Events

  • banner-opening: Fired when the banner starts opening.
  • banner-opened: Fired when the banner finishes opening.
  • banner-closing: Fired when the banner starts closing (detail.reason).
  • banner-closed: Fired when the banner finishes closing (detail.reason).
  • banner-primary-action: Fired when the built-in primary action button is clicked (cancelable).
  • banner-secondary-action: Fired when the built-in secondary action button is clicked (cancelable).

Actions

Code
<div style="display: flex; flex-direction: column; gap: 12px;">
    <mdc-banner icon="credit_card" primary-action="Update payment" secondary-action="Dismiss" dismiss-on-action>
        Your subscription payment method has expired.
    </mdc-banner>

    <mdc-banner icon="lock" no-divider variant="surface-container">
        Using slotted custom <code>&lt;mdc-button&gt;</code> actions and <code>no-divider</code>.
        <mdc-button slot="secondary-action" variant="text">Cancel</mdc-button>
        <mdc-button slot="primary-action" variant="filled">Grant access</mdc-button>
    </mdc-banner>
</div>

Icon

Code
<div style="display: flex; flex-direction: column; gap: 12px;">
    <mdc-banner icon="notifications" primary-action="Enable">
        Standard 24px leading icon without container.
    </mdc-banner>

    <mdc-banner icon="security" icon-container variant="primary-container" primary-action="Verify">
        40px circular tinted icon container enabled via <code>icon-container</code>.
    </mdc-banner>

    <mdc-banner primary-action="Acknowledge">
        Banner without a leading icon aligns text directly to the inline start edge.
    </mdc-banner>
</div>

Layout

Code
<div style="display: flex; flex-direction: column; gap: 16px;">
    <mdc-banner layout="single-line" icon="cloud_off" primary-action="Retry">
        Single-line layout keeps icon, message, and action on one horizontal row.
    </mdc-banner>

    <mdc-banner layout="stacked" icon="system_update" headline="Update available" primary-action="Update now" secondary-action="Later">
        Stacked layout places actions on a right-aligned row beneath the message.
    </mdc-banner>

    <mdc-banner layout="auto" icon="warning" primary-action="Review" secondary-action="Dismiss">
        Auto layout switches to stacked automatically when two actions or a headline are present, or on narrow screens.
    </mdc-banner>
</div>

Open

Code
<div style="display: flex; flex-direction: column; gap: 12px;">
    <div>
        <mdc-button id="banner-toggle-btn" variant="tonal">Toggle Banner</mdc-button>
    </div>
    <div style="border: 1px solid var(--md-sys-color-outline-variant, #ccc); border-radius: 8px; overflow: hidden;">
        <mdc-banner
            id="demo-interactive-banner"
            open
            icon="wifi_off"
            variant="error-container"
            primary-action="Reconnect"
            secondary-action="Dismiss"
            dismiss-on-action
        >
            No internet connection. Reconnect to continue syncing your workspace.
        </mdc-banner>
        <div style="padding: 16px;">
            Page content below the banner shifts smoothly when the banner expands or collapses.
        </div>
    </div>
</div>
<script type="module">
    const root = document.currentScript?.getRootNode?.() ?? document
    const btn = root.getElementById?.('banner-toggle-btn') ?? document.getElementById('banner-toggle-btn')
    const banner = root.getElementById?.('demo-interactive-banner') ?? document.getElementById('demo-interactive-banner')
    btn?.addEventListener('click', () => {
        if (!banner) return
        banner.open = !banner.open
    })
</script>

Variant

Code
<div style="display: flex; flex-direction: column; gap: 12px;">
    <mdc-banner variant="surface" icon="info" primary-action="Got it">
        Surface variant (default) — standard in-flow notification banner.
    </mdc-banner>
    <mdc-banner variant="surface-container" icon="sync" primary-action="Sync now">
        Surface Container variant — subtle contrast against page background.
    </mdc-banner>
    <mdc-banner variant="primary-container" icon="campaign" primary-action="Learn more">
        Primary Container variant — highlighted feature announcement.
    </mdc-banner>
    <mdc-banner variant="secondary-container" icon="tips_and_updates" primary-action="Apply">
        Secondary Container variant — helpful suggestion or tip.
    </mdc-banner>
    <mdc-banner variant="tertiary-container" icon="new_releases" primary-action="Explore">
        Tertiary Container variant — accent notice.
    </mdc-banner>
    <mdc-banner variant="error-container" icon="wifi_off" primary-action="Retry" secondary-action="Offline mode">
        Error Container variant — connection lost. Changes will sync when back online.
    </mdc-banner>
    <mdc-banner variant="inverse-surface" icon="dark_mode" primary-action="Switch">
        Inverse Surface variant — high-contrast banner.
    </mdc-banner>
</div>