Skip to main content

Badges

Badges display micro information, and let users perform micro (and usually third-party-related) actions in the user interface. Actions range from sharing a link, to navigating to a greater details page.

Usage

HTML

<a href="#" class="hs-badge">
<span class="hs-badge__label">HSBadge</span>
</a>

Using an icon

Badges optionally let you display an icon. Icons can be images, svg, or a special icon font.

<a href="#" class="hs-badge">
<i class="hs-badge__icon">
<!-- SVG, image, or font icon -->
</i>
<span class="hs-badge__label">HSBadge</span>
</a>

SCSS

@use 'node_modules/@devprotocol/hashi';
@use 'node_modules/@devprotocol/hashi/hs-badge';

@include hashi.init {
@include hs-badge.render();
}

API

CSS Classes

These are used to extend and modify the styles of a component on the markup.

Anatomical Classes

These classes make up the elements inside a component.

ClassEffect
.hs-badgeMain badge class.
.hs-badge__labelClass for the badge label.
.hs-badge__iconClass for the badge icon.

Custom Properties

These are for creating your own component theme classes that you can append to the parent element markup.

PropertyEffect
--hs-badge-fillChanges the badge's background color.
--hs-badge-inkChanges the badge's text color.
--hs-badge-borderChanges the badge's border color.
--hs-badge-radiusChanges the badge's border radius.
--hs-badge-gapChanges the badge's label and icon gap.
--hs-badge-paddingChanges the badge's padding.
--hs-badge-inkChanges the badge's label color.
--hs-badge-sizeChanges the badge's label size.
--hs-badge-shadowChanges the badge's shadow.
--hs-badge-weightChanges the badge's weight.
--hs-badge-icon-inkChanges the badge's icon color.
--hs-badge-icon-sizeChanges the badge's icon size.

Example

.my-badge-theme {
--hs-badge-fill: #232323;
--hs-badge-ink: lime;
--hs-badge-border: var(--hs-badge-fill);

&:hover {
--hs-badge-fill: #353535;
}

&:active {
--hs-badge-fill: #535353;
}
}

Configuring styles

Here are all the themeable properties for this component. The directions to use these properties are located in the render API.

$fill: 'primary-600' !default;
$ink: 'primary-ink' !default;
$border: $fill !default;

$radius: 'small' !default;
$padding: ('xs' 'sm') !default;
$gap: 'xs' !default;

$label-typography: 'small' !default;

Extending styles

If you wish to extend the component styles, the extend() API might come in handy.