Skip to content

Badge - CSS Component

The Badge component can be used imported from:

Playground

Construction

The CSS component uses any container tag, but we recommend the use of <div> or <span> HTML tags with the z-badge HTML custom attribute and the content to have the Badge placed inside the tag.

Important!

In the examples of the following explanations we are applying a style to the content of the badge to better visualizing the positioning of the badge in relation to the content.

z-badge

type

The z-badge parameter will use the dot configuration as default, matching the dot variant of the specifications.

Badged content

For the other two types, text and icon, we can specify the type as the first param of the z-badge attribute.

  • The text variant will use z-badge="text" and will receive the text to be shown in another attribute called text. If not text is provided, the badge will look like the dot base variant.

    Badged content
  • The icon variant will use z-badge="icon" and will receive the icon to be shown in another attribute called icon. Make sure that you use the line version of the icons for the Badge. Otherwise, the icon won't be shown to avoid misusage of the component.

    Badged content

The z-badge attribute has two optional modifiers that can de applied in order after the type, using colon (:) as the separator. The pattern would be <?type><?style><?size>

style

The first modifier is style, that can receive the value outline to make the badge separate from the content by a line that matches the background. This uses the --z-bg variable, so it's important that this is changed within the context. The type can be skipped if the value is dot.

Badged content
Badged content
size

The second modifier is size, which can have the values xs, s, m (default), or l. Must be always at the end and the z-badge attribute. The type can be skipped if the value is dot.

Badged content
Badged content
Badged content
Badged content

fill

The attribute fill changes the color of the badge background. The value names available are defined using the color palettes (check the colors section), and the possible values are: bold, blue-dark, blue-sky, moss, peach, lemon, or dove. The color of the text adapts for contrast.

Badged content
Badged content
Badged content
Badged content

Special uses

Badge for Profile

When Badge is used with Profile, the position is adjusted:

Notifications

We can use the Icon to make a notifications alert:

Browser support

Detected engine:  

  • Chromium

  • Webkit

  • Gecko

HTML Examples

CodeSandbox example