component :: Banner

The .banner component is the thin announcement bar at the very top of the page, optionally dismissible (remembered in localStorage).

FileDescriptionSource
component.banner.cssAll banner stylesGithub
Banner.astroThe Astro componentGithub
icons/x.svgDismiss iconGithub
--banner-* block in default themeTheme tokens (see table below)Github

HTML

<aside class="banner">
<div class="banner_content">
<p>mCSS v1 is out! <a href="/blog/v1">Read the announcement</a></p>
</div>
<button class="banner_close" aria-label="Dismiss announcement"><svg>[…]</svg></button>
</aside>

For a dismissible plain-HTML banner, copy the small inline script from the bottom of Banner.astro: it removes the banner when the stored key exists (before paint, so an already-dismissed banner never flashes) and stores the key on click.

Looking for the big closing call-to-action band instead? That’s a Section recipe, not a separate component.

Custom properties

The following custom properties are available in the default theme:

PropertyDescription
--banner-colorBanner text color.
--banner-background-colorBanner background.

Astro component

PropTypeDefaultDescription
idstringundefinedRequired when dismissible; keys the localStorage entry (mcss-banner-<id>). Use a new id per campaign so a new announcement shows again.
dismissiblebooleanfalseAdds the close button + persistence script.
dismissLabelstring"Dismiss announcement"Accessible name of the close button.
classstringundefinedAdditional CSS classes.

The default slot is the banner content. Place the banner as the first child of <body>, above the header.

Examples