Zum Inhalt springen

TagBadge

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

The TagBadge component renders a single tag as a styled pill-shaped badge with optional icon and count.

See live demo →

import { TagBadge } from 'starlight-tags/components';
PropTypeDefaultDescription
tagIdstring-Tag ID to display (fetches data automatically)
tagProcessedTag-Pre-fetched tag object (for advanced use)
size'small' | 'medium' | 'large''medium'Badge size
variant'solid' | 'outline' | 'ghost''solid'Visual style
showCountbooleanfalseShow page count
showIconbooleantrueShow tag icon
clickablebooleantrueRender as link
import { TagBadge } from 'starlight-tags/components';
<TagBadge tagId="authentication" />

That’s it! The component fetches tag data automatically.

Filled background with the tag’s color:

<TagBadge tagId="authentication" variant="solid" />

Bordered with transparent background:

<TagBadge tagId="authentication" variant="outline" />

Subtle background tint:

<TagBadge tagId="authentication" variant="ghost" />
<TagBadge tagId="authentication" size="small" />
<TagBadge tagId="authentication" size="medium" />
<TagBadge tagId="authentication" size="large" />

Show the number of pages with this tag:

<TagBadge tagId="authentication" showCount />

Hide the tag icon:

<TagBadge tagId="authentication" showIcon={false} />

Render as a span instead of a link:

<TagBadge tagId="authentication" clickable={false} />

Display several tags together:

import { TagBadge } from 'starlight-tags/components';
<div style="display: flex; gap: 0.5rem; flex-wrap: wrap;">
<TagBadge tagId="authentication" />
<TagBadge tagId="rest-api" />
<TagBadge tagId="webhooks" variant="outline" />
</div>

For advanced use cases where you already have tag data:

---
import { TagBadge } from 'starlight-tags/components';
const { tags } = Astro.locals.starlightTags;
const authTag = tags.get('authentication');
---
<TagBadge tag={authTag} variant="outline" showCount />

The component uses CSS custom properties that inherit from Starlight’s theme:

  • Tag color from tags.yml is applied via --tag-color
  • Falls back to --sl-color-accent if no color specified

Override styles using CSS:

/* In your custom CSS */
.fb-tag {
font-family: var(--sl-font-mono);
}
.fb-tag--solid {
box-shadow: none;
}