component :: Tags
The .tags component styles a list of tags. It supports both list and inline
layouts, is accessible by default, and customizable via CSS custom properties.
| File Name | class | Source |
|---|
component.tags.css | .tags | Github |
HTML
Custom properties
The following custom properties are available in the default theme:
| Property | Description |
|---|
--tags-padding | Tag padding. |
--tags-font-size | Tag font size. |
--tags-color | Tag text color. |
--tags-background-color | Tag background color. |
--tags-background-color-hover | Tag hover background color. |
--tags-radius | Tag border radius. |
Available modifiers
| Modifier | Description |
|---|
.tags | Default style (list layout). |
.tags-inline | Inline layout using flex. |
Astro component
| Prop | Type | Default | Description |
|---|
tagList | string[] | [] | Array of tag strings to display. |
variant | string | inline | Inline or list layout. |
url | string | /tags | Base URL to prepend to each tag. |
extraClass | string | undefined | Additional CSS, useful for helper classes. |
ariaLabel | string | 'Tags' | Accessible label for the tag list. |
data-testid | string | 'tags' | Test ID for testing purposes. |
Examples
---
import Tags from '../components/Tags.astro';
const { frontmatter } = Astro.props;
---
<Tags tagList={frontmatter.tags} url="/tags" />
HTML example (list layout)
<ul class="tags">
<li>
<a href="/tags/css">css</a>
</li>
<li>
<a href="/tags/astro">astro</a>
</li>
<li>
<a href="/tags/basics">basics</a>
</li>
</ul>
HTML example (inline layout)
<ul class="tags tags-inline">
<li>
<a href="/tags/css">css</a>
</li>
<li>
<a href="/tags/astro">astro</a>
</li>
<li>
<a href="/tags/basics">basics</a>
</li>
</ul>