Banners

Banners are full-width notices used for system and engagement messaging. They are highly intrusive and should be used only when essential information needs to be conveyed to the user.

Classes

ClassDescriptionParentModifies
.s-bannerBase banner element.N/AN/A
.s-banner--actionsContainer styling for banner actions including the dismiss button..s-bannerN/A
.s-banner--dismissApplies to child button element within the banner to position it appropriately..s-bannerN/A
.s-banner__importantApplies an important visual style. This should be used for time-sensitive, pressing information that needs to be noticed by the user.N/A.s-banner
.s-banner__infoApplies info (blue) visual styles.N/A.s-banner
.s-banner__successApplies success (green) visual styles.N/A.s-banner
.s-banner__warningApplies warning (yellow) visual styles.N/A.s-banner
.s-banner__dangerApplies danger (red) visual styles.N/A.s-banner
.s-banner__featuredApplies featured (purple) visual styles.N/A.s-banner
.s-banner__activityApplies activity (pink) visual styles.N/A.s-banner
.is-pinnedPins the banner to the top of the browser window.N/A.s-banner

Usage guidelines

System banners are used for system messaging. They are full-width notices placed in one of two locations:

  • Pinned to the top of the browser window — Use when the banner relates to the entire website (e.g. the site is in read-only mode). Add .is-pinned to pin the banner above all other content including the topbar.
  • Below the top navigation bar — The default placement. Use when the banner affects only a particular area of the product (e.g. a subscription is about to expire).

Refer to the Classes section for more information on how to apply the correct styles.

Examples

Base

<div class="s-banner" role="alert" aria-hidden="false"></div>
<div class="s-banner s-banner__important" role="alert" aria-hidden="false"></div>

Info

<div class="s-banner s-banner__info" role="alert" aria-hidden="false"></div>
<div class="s-banner s-banner__info s-banner__important" role="alert" aria-hidden="false"></div>

Success

<div class="s-banner s-banner__success" role="alert" aria-hidden="false"></div>
<div class="s-banner s-banner__success s-banner__important" role="alert" aria-hidden="false"></div>

Warning

<div class="s-banner s-banner__warning" role="alert" aria-hidden="false"></div>
<div class="s-banner s-banner__warning s-banner__important" role="alert" aria-hidden="false"></div>

Danger

<div class="s-banner s-banner__danger" role="alert" aria-hidden="false"></div>
<div class="s-banner s-banner__danger s-banner__important" role="alert" aria-hidden="false"></div>
<div class="s-banner s-banner__featured" role="alert" aria-hidden="false"></div>
<div class="s-banner s-banner__featured s-banner__important" role="alert" aria-hidden="false"></div>

Activity

<div class="s-banner s-banner__activity" role="alert" aria-hidden="false"></div>
<div class="s-banner s-banner__activity s-banner__important" role="alert" aria-hidden="false"></div>

JavaScript

The .s-banner component includes a controller to show and hide the banner programitically. While it is optional, at least including the functionality to close the banner is recommended.

Example

<div
    role="alert"
    id="example-banner"
    class="s-banner"
    aria-labelledby="example-message"
    aria-hidden="true"
    data-controller="s-banner"
    data-s-banner-target="banner">
    Example banner
</div><button
    data-toggle="s-banner"
    data-target="#example-banner">
    Show banner
</button>
document.querySelector(".js-banner-toggle").addEventListener("click", function(e) {
    Stacks.showBanner(document.querySelector("#example-banner"));
});

Attributes

AttributeDescriptionApplies to
data-controller="s-banner"Wires up the element to the banner controller. This may be a `.s-banner` element or a wrapper element.Controller element
data-s-banner-target="banner"Wires up the element that is to be shown/hidden..s-banner element
data-s-banner-remove-when-hidden="true"(optional) Removes the banner from the DOM entirely when it is hidden.Controller element

Events

EventDescriptionApplies to
s-banner:showFires immediately before showing the banner. Calling `.preventDefault()` cancels the display of the banner.Banner target
s-banner:shownFires after the banner has been visually shown.Banner target
s-banner:hideFires immediately before hiding the banner. Calling `.preventDefault()` cancels the removal of the banner.Banner target
s-banner:hiddenFires after the banner has been visually hidden.Banner target

Event details

event.detailDescriptionApplicable events
dispatcherContains the `Element` that initiated the event. For instance, the button clicked to show, the element clicked outside the banner that caused it to hide, etc.N/A

Helpers

FunctionDescriptionApplies to
Stacks.showBannerHelper to manually show an s-banner element via external JS.Controller element
Stacks.hideBannerHelper to manually hide an s-banner element via external JS.Controller element