Heading Hierarchy and Semantic HTML Guidelines
Heading Hierarchy and Semantic HTML Guidelines
Section titled “Heading Hierarchy and Semantic HTML Guidelines”This document provides guidelines for maintaining proper heading hierarchy and semantic HTML structure in the Sparkle Design System documentation.
Heading Hierarchy Rules
Section titled “Heading Hierarchy Rules”1. Page Title = H1 (Automatic)
Section titled “1. Page Title = H1 (Automatic)”- Rule: Never use
# H1in markdown content - Reason: Astro Starlight automatically creates H1 from the frontmatter
title - Correct: Use frontmatter
title: "Page Title" - Incorrect:
# Page Titlein content
2. Content Starts with H2
Section titled “2. Content Starts with H2”-
Rule: First heading in content should be
## H2 -
Example:
---title: Component Overview---## IntroductionContent about the component...## Usage ExamplesHow to use the component...
3. No Skipping Levels
Section titled “3. No Skipping Levels”- Rule: Progress logically H2 → H3 → H4 → H5 → H6
- Correct: H2 → H3 → H4
- Incorrect: H2 → H4 (skipping H3)
4. Proper Nesting
Section titled “4. Proper Nesting”-
Rule: Subsections should be nested under parent sections
-
Example:
## Main Topic (H2)Content about main topic...### Subtopic A (H3)Content about subtopic A...#### Implementation Details (H4)Specific implementation info...### Subtopic B (H3)Content about subtopic B...## Another Main Topic (H2)
5. API Documentation Exception
Section titled “5. API Documentation Exception”- Rule: Auto-generated API docs use a special layout that handles H1 conflicts
- Implementation: Use
layout: ~/layouts/api.astroin frontmatter - Note: This layout visually adjusts heading levels for proper hierarchy
Semantic HTML Components
Section titled “Semantic HTML Components”PageMain
Section titled “PageMain”Use for main content wrapper:
import PageMain from '~/components/layout/PageMain.astro'
<PageMain> <!-- Main page content --></PageMain>ContentSection
Section titled “ContentSection”Use for logical content sections:
import ContentSection from '~/components/layout/ContentSection.astro'
<ContentSection ariaLabel="Getting Started" id="getting-started"> ## Getting Started Content...</ContentSection>ContentArticle
Section titled “ContentArticle”Use for self-contained content pieces:
import ContentArticle from '~/components/layout/ContentArticle.astro'
<ContentArticle ariaLabel="Button Component Guide"> ## Button Component Complete guide to using buttons...</ContentArticle>SemanticHeading
Section titled “SemanticHeading”Use when you need programmatic heading control:
import SemanticHeading from '~/components/layout/SemanticHeading.astro'
<SemanticHeading level={2} id="section-intro"> Section Introduction</SemanticHeading>ContentNavigation
Section titled “ContentNavigation”Use for navigation elements:
import ContentNavigation from '~/components/layout/ContentNavigation.astro'
<ContentNavigation ariaLabel="Page navigation" type="pagination"> <!-- Navigation links --></ContentNavigation>ContentAside
Section titled “ContentAside”Use for supplementary content:
import ContentAside from '~/components/layout/ContentAside.astro'
<ContentAside type="callout" ariaLabel="Important note"> **Note**: This is important information.</ContentAside>Page Structure Templates
Section titled “Page Structure Templates”Standard Documentation Page
Section titled “Standard Documentation Page”---title: Page Titledescription: Page description for SEO and navigation---
import ContentSection from '~/components/layout/ContentSection.astro'import ContentAside from '~/components/layout/ContentAside.astro'
## OverviewBrief introduction to the topic...
<ContentSection ariaLabel="Main concepts" id="concepts">
## Key ConceptsExplanation of key concepts...
### Concept ADetails about concept A...
### Concept BDetails about concept B...
</ContentSection>
<ContentAside type="note" ariaLabel="Usage tip">**Tip**: Remember to follow these best practices...</ContentAside>
<ContentSection ariaLabel="Examples" id="examples">
## ExamplesPractical examples...
### Basic ExampleSimple example...
### Advanced ExampleComplex example...
</ContentSection>Component Documentation Page
Section titled “Component Documentation Page”---title: Component Namedescription: Component description and purposecategory: formcomponentName: ComponentName---
import ComponentShowcase from '~/components/showcase/ComponentShowcase.astro'import ContentSection from '~/components/layout/ContentSection.astro'
## OverviewWhat this component does...
<ContentSection ariaLabel="Usage guide" id="usage">
## UsageHow to use this component...
### Basic UsageSimple usage example...
### Advanced UsageComplex usage patterns...
</ContentSection>
<ContentSection ariaLabel="API reference" id="api">
## API ReferenceComponent props and methods...
### PropsList of component props...
### MethodsAvailable methods...
</ContentSection>API Reference Page
Section titled “API Reference Page”---title: Module API Referencedescription: API reference for the modulelayout: ~/layouts/api.astro---
## Module OverviewBrief description of the module...
## ClassesAvailable classes...
## FunctionsAvailable functions...
## Type DefinitionsAvailable types and interfaces...Accessibility Considerations
Section titled “Accessibility Considerations”1. Skip Navigation
Section titled “1. Skip Navigation”- All pages should include skip navigation for keyboard users
- Use
<SkipNavigation />component at the beginning of pages
2. Landmark Roles
Section titled “2. Landmark Roles”- Use semantic HTML elements with proper roles
- Main content in
<main>(handled by PageMain) - Navigation in
<nav>(handled by ContentNavigation) - Complementary content in
<aside>(handled by ContentAside)
3. Heading Landmarks
Section titled “3. Heading Landmarks”- Screen readers use headings for navigation
- Proper hierarchy allows users to understand content structure
- Each section should have a meaningful heading
4. ARIA Labels
Section titled “4. ARIA Labels”- Provide
ariaLabelfor complex sections - Use descriptive labels that explain the content purpose
- Avoid redundant labels (don’t repeat visible text)
Validation Tools
Section titled “Validation Tools”1. Browser DevTools
Section titled “1. Browser DevTools”- Use Accessibility tab in DevTools
- Check heading structure in Elements panel
- Verify landmark roles and ARIA labels
2. Screen Reader Testing
Section titled “2. Screen Reader Testing”- Test with VoiceOver (macOS) or NVDA (Windows)
- Navigate by headings (H key in screen readers)
- Verify logical content flow
3. Automated Testing
Section titled “3. Automated Testing”- Use axe-core for automated accessibility testing
- Include in CI/CD pipeline for continuous validation
- Focus on heading hierarchy and landmark structure
Common Mistakes to Avoid
Section titled “Common Mistakes to Avoid”1. Multiple H1 Elements
Section titled “1. Multiple H1 Elements”- Problem: Using
# Headingin content when page already has H1 from title - Solution: Start content with
## Heading
2. Skipping Heading Levels
Section titled “2. Skipping Heading Levels”- Problem: Going from H2 directly to H4
- Solution: Use logical progression H2 → H3 → H4
3. Decorative Headings
Section titled “3. Decorative Headings”- Problem: Using headings for visual styling instead of structure
- Solution: Use CSS classes for styling, headings for structure
4. Missing Semantic Elements
Section titled “4. Missing Semantic Elements”- Problem: Using
<div>for everything - Solution: Use
<main>,<section>,<article>,<nav>,<aside>
5. Poor ARIA Labels
Section titled “5. Poor ARIA Labels”- Problem: Generic labels like “section” or “content”
- Solution: Descriptive labels like “Getting started guide” or “API reference”
Review Checklist
Section titled “Review Checklist”Before publishing documentation:
- Page title is in frontmatter, not H1 in content
- Content starts with H2
- No heading levels are skipped
- Logical content hierarchy
- Semantic HTML elements used appropriately
- ARIA labels are descriptive and helpful
- Skip navigation is available
- Content is accessible to screen readers
- All internal links work correctly
- Table of contents reflects actual structure