PageTags
The PageTags component automatically displays tags from the current page’s frontmatter. It’s the easiest way to show tags on your documentation pages.
Import
Section titled “Import”import { PageTags } from 'starlight-tags/components';| Prop | Type | Default | Description |
|---|---|---|---|
layout | 'inline' | 'block' | 'inline' | Display layout |
variant | 'solid' | 'outline' | 'ghost' | 'outline' | Badge visual style |
size | 'small' | 'medium' | 'large' | 'small' | Badge size |
showIcon | boolean | true | Show tag icons |
label | string | boolean | undefined | Pass true for localized default label, or a custom string |
Basic Usage
Section titled “Basic Usage”Simply drop the component into any MDX page that has tags in its frontmatter:
---title: Configuration Guidetags: - configuration - guide - getting-started---
import { PageTags } from 'starlight-tags/components';
# Configuration Guide
<PageTags />
Your content here...Layouts
Section titled “Layouts”Inline (Default)
Section titled “Inline (Default)”Tags flow with surrounding content:
<PageTags layout="inline" />Tags take full width with borders:
<PageTags layout="block" />With Label
Section titled “With Label”Add a text label before the tags. Use true for the localized default (“Tags:”) or pass a custom string:
{/* Use localized default label */}<PageTags label={true} />
{/* Use custom label */}<PageTags label="Topics:" />Renders as: Topics: [tag1] [tag2] [tag3]
<PageTags size="small" /><PageTags size="medium" /><PageTags size="large" />Style Variants
Section titled “Style Variants”<PageTags variant="solid" /><PageTags variant="outline" /> <!-- Default --><PageTags variant="ghost" />Without Icons
Section titled “Without Icons”<PageTags showIcon={false} />Positioning
Section titled “Positioning”Place the component where you want tags to appear:
At the Top
Section titled “At the Top”---title: Plugin Development Guidetags: [plugins, guide]---
import { PageTags } from 'starlight-tags/components';
<PageTags layout="block" />
# Plugin Development Guide
Content here...At the Bottom
Section titled “At the Bottom”---title: Plugin Development Guidetags: [plugins, guide]---
import { PageTags } from 'starlight-tags/components';
# Plugin Development Guide
Content here...
---
<PageTags label="Tagged:" />Multiple Locations
Section titled “Multiple Locations”---title: Plugin Development Guidetags: [plugins, guide]---
import { PageTags } from 'starlight-tags/components';
<PageTags layout="block" variant="ghost" />
# Plugin Development Guide
Content here...
---
<PageTags label="Related topics:" size="small" />Complete Example
Section titled “Complete Example”---title: Advanced Plugin Developmentdescription: Complete guide to building custom pluginstags: - plugins - advanced - guide - components---
import { PageTags } from 'starlight-tags/components';
<PageTags layout="block" variant="outline" size="medium" label="This guide covers:" />
# Advanced Plugin Development
In this guide, you'll learn how to build custom plugins...
## Prerequisites
Before starting, make sure you understand:- Basic configuration- Component fundamentals
## Getting Started
...
---
<PageTags label="Topics covered:" size="small" variant="ghost" />How It Works
Section titled “How It Works”The PageTags component:
- Reads the
tagsarray from the current page’s frontmatter - Checks the
hideTagsfrontmatter property - Fetches tag data from middleware (
Astro.locals.starlightTags) - Renders each tag using the
TagBadgecomponent
The component renders nothing if:
- No tags are defined in the frontmatter
hideTags: trueis set in the frontmatter
Hiding Tags
Section titled “Hiding Tags”Use the hideTags frontmatter property to hide tags on specific pages while still associating the page with those tags:
---title: Internal Configuration Referencetags: - configuration - referencehideTags: true---
import { PageTags } from 'starlight-tags/components';
<PageTags /> <!-- Renders nothing because hideTags is true -->
This page is still listed on the /tags/configuration and /tags/reference pages,but tags aren't displayed here.This is useful when you want pages to appear in tag listings without displaying the tags on the page itself.
PageTags vs PageWithTags
Section titled “PageTags vs PageWithTags”Wondering which component to use? Here’s a quick comparison:
| Feature | PageTags | PageWithTags |
|---|---|---|
| Auto-reads frontmatter | Yes | Yes |
| Accepts tagIds prop | No | Yes |
| Wraps content | No | Yes (via slot) |
| Position control | Manual placement | top / bottom / both |
| Separator line | No | Yes (bottom position) |
| “Tags” title | No | Optional |
| Best for | Drop-in tag display | Layout templates |
When to Use PageTags
Section titled “When to Use PageTags”Choose PageTags when you want:
- A simple drop-in solution — just add
<PageTags />anywhere in your MDX - Full control over placement within your content
- Automatic tag detection from frontmatter with no extra setup
<PageTags /> <!-- That's it! -->When to Use PageWithTags
Section titled “When to Use PageWithTags”Choose PageWithTags when you need:
- Tags that frame your content at the top, bottom, or both
- Consistent tag positioning across multiple pages
- The ability to specify which tags to display via
tagIds
<PageWithTags tags={customTags} position="both"> <YourContent /></PageWithTags>