Tag Group
TagGroup is a headless container for a collection of related tags. It uses the ARIA group role with an accessible label to semantically associate tag elements, making the collection understandable to screen readers and other assistive technologies.
This component is useful for displaying categories, skills, technologies, or any set of labels that belong together. Consumers provide the individual tag elements as children and bring their own styling.
Example
Show demo markup
<div class="tag-group"><span class="tag">Design</span><span class="tag">Development</span><span class="tag">Testing</span></div>
Usage example
<script lang="ts">
import TagGroup from "./TagGroup.svelte";
import Tag from "../Tag/Tag.svelte";
</script>
<TagGroup label="Technologies">
<Tag label="Technology">Svelte</Tag>
<Tag label="Technology">TypeScript</Tag>
<Tag label="Technology">Vite</Tag>
</TagGroup>
Show Svelte source
// In your Svelte component:
import TagGroup from "lily-design-system-svelte-headless/components/TagGroup/TagGroup.svelte";
<TagGroup>
<!-- list children -->
</TagGroup>
Usage
<TagGroup label="Patient statuses">
<Tag label="Status: Verified">Verified</Tag>
<Tag label="Status: NHS patient">NHS patient</Tag>
<Tag label="Status: Review due">Review due</Tag>
</TagGroup>
Props
label: string (required) -- accessible name for the group via aria-label
children: slot (required) -- tag elements to render inside the group
...restProps: unknown -- additional attributes spread onto the container <div>
Keyboard Interactions
None -- this component is a passive container. Keyboard behavior depends on the child tag elements provided by the consumer.
ARIA
role="group" -- identifies the container as a semantic grouping of related elements
aria-label={label} -- provides an accessible name describing the purpose of the tag collection
When to Use
- Use to display multiple tags together, such as statuses or categories applied to a single item
- Use within cards, table rows, or list items where an item has several attributes to show
- Use to visually group related status indicators with consistent spacing
When Not to Use
- Do not use for a single tag -- render the Tag component directly
- Do not use for interactive chip or filter patterns -- use ToggleGroup or SegmentGroup instead
- Do not use for tag creation and removal -- use TagInput for editable tag lists
Headless
This headless component renders a <div> with role="group" and aria-label to semantically associate child tag elements. It provides grouping semantics for assistive technologies. The consumer provides all visual styling including layout (flex, grid, wrap), spacing, and gap between tags.
Styles
The consumer provides all CSS styling. The component renders with a .tag-group class for targeting. No default styles are included — this is a fully headless component.
Testing
- Verify the component renders a
<div> element with class tag-group
- Verify role="group"` -- identifies the container as a semantic grouping of related elements
- Verify aria-label={label}` -- provides an accessible name describing the purpose of the tag collection
- Verify pass-through attributes are applied
Advice
- Designers: Use a horizontal flex-wrap layout with consistent gaps between tags. Consider a label or heading above the group to visually identify the tag category.
- Developers: Use a descriptive
label prop that names the collection (e.g., "Technologies", "Skills"). Pair TagGroup with Tag children for proper semantic structure.
Implementation Notes
- Renders a
<div> with role="group" to semantically group child tag elements
- Uses
aria-label for an accessible name describing the group
- Accepts a
children slot for rendering tag elements inside the group
- Spreads
restProps onto the container for consumer customization
- pattern: standard props destructuring with typed props
Composition
TagGroup uses the Group/Item composition pattern. Place Tag components as children inside TagGroup. The TagGroup provides the role="group" container with an accessible label, while each Tag provides an individual labeled element within the group.
Related components
tag — a keyword label for categorizing content
tag-input — an input for adding and removing tags
References
- WAI-ARIA group role: https://www.w3.org/TR/wai-aria-1.2/#group
Canonical contract
Generated from this component's canonical metadata — the machine-checked source the implementations are held to.
Metadata
- Component: tag-group
- PascalCase: TagGroup
- Description: a group of tag elements
- Status: stable — exercised in composed page flows under e2e and axe, beyond the per-component checks
- HTML tag: <div>
- CSS class: .tag-group
- Interactive: no
ARIA
role="group" -- identifies the container as a semantic grouping of related elements aria-label={label} -- provides an accessible name describing the purpose of the tag collection
Keyboard
- No keyboard interactions — this is a passive element
Props
label: string (required) -- accessible name for the group via aria-label children: slot (required) -- tag elements to render inside the group ...restProps: unknown -- additional attributes spread onto the container <div>