use-semantic-html
Installation
SKILL.md
Summary
Prioritize Semantic HTML tags (e.g., <article>, <section>, <nav>, <main>) over generic <div> or <span> elements. Use div/span only when no semantic tag applies, or for pure styling wrappers.
Rationale
- Accessibility: Screen readers rely on semantic landmarks (landmarks) to navigate. A
<nav>or<main>element allows users to skip repetitive content. - SEO: Search engines use tag hierarchy to understand content importance and relationship.
- Maintainability: Semantic tags communicate the code's intent (
<article class="post">vs<div>). - Testability: Semantic structure enables robust testing selectors like
getByRole('navigation')orgetByRole('article'), which are more resilient to design changes than CSS classes.
Guidance
- Rule: Default to semantic tags.
header,footer,main: High-level page structure.nav: Navigation links.article: Self-contained content (blog post, comment).section: Thematic grouping of content with a heading.
- Avoid: "Div Soup" (nested divs with no semantic meaning).
- Exception:
- Explicit Role: A
divorspanwith a valid WAI-ARIArole(e.g.,<div role="button">) is acceptable if a native element cannot be used (though native is still preferred). - Styling:
divandspanare perfectly fine for layout/styling wrappers (e.g., Flexbox containers) that have no semantic meaning.
- Explicit Role: A