AgentSkillsCN

html

在 Web 开发中践行语义化 HTML 的最佳实践。合理使用各类 HTML 元素、规范文档结构、优化表单设计与元数据配置。触发时机:在编写 HTML 标记、构建文档结构,或实施语义化 HTML 元素时。

SKILL.md
--- frontmatter
name: html
description: Semantic HTML best practices for web development. Proper element usage, document structure, forms, metadata. Trigger: When writing HTML markup, creating document structure, or implementing semantic HTML elements.
skills:
  - conventions
  - a11y
allowed-tools:
  - documentation-reader
  - web-search

HTML Skill

Overview

Guidance for writing semantic, accessible HTML following modern web standards.

Objective

Enable developers to create properly structured HTML with semantic elements, accessibility attributes, and best practices.


When to Use

Use this skill when:

  • Writing HTML markup for web pages
  • Creating document structure with semantic elements
  • Building forms with proper labels and inputs
  • Adding metadata and head elements
  • Ensuring valid, semantic HTML

Don't use this skill for:

  • React JSX patterns (use react skill)
  • Accessibility specifics (use a11y skill for detailed guidance)

Critical Patterns

✅ REQUIRED: Use Semantic Elements

html
<!-- ✅ CORRECT: Semantic elements -->
<header>
  <nav>
    <ul>
      <li><a href="/">Home</a></li>
    </ul>
  </nav>
</header>
<main>
  <article>
    <h1>Title</h1>
    <p>Content</p>
  </article>
</main>
<footer>Footer content</footer>

<!-- ❌ WRONG: Generic divs -->
<div class="header">
  <div class="nav">...</div>
</div>
<div class="main">...</div>

✅ REQUIRED: Proper Heading Hierarchy

html
<!-- ✅ CORRECT: Sequential hierarchy -->
<h1>Page Title</h1>
<h2>Section</h2>
<h3>Subsection</h3>

<!-- ❌ WRONG: Skipping levels -->
<h1>Page Title</h1>
<h4>Section</h4>
<!-- Skipped h2, h3 -->

✅ REQUIRED: Button vs Anchor

html
<!-- ✅ CORRECT: Button for actions -->
<button type="button" onclick="doSomething()">Click</button>

<!-- ✅ CORRECT: Anchor for navigation -->
<a href="/page">Go to Page</a>

<!-- ❌ WRONG: Anchor for actions -->
<a href="#" onclick="doSomething()">Click</a>

Conventions

Refer to conventions for:

  • Code organization
  • Documentation

Refer to a11y for:

  • Semantic elements
  • ARIA attributes
  • Keyboard navigation

HTML Specific

  • Use semantic elements (<nav>, <main>, <article>)
  • Maintain proper heading hierarchy
  • Include alt text for images
  • Use <button> for actions, <a> for navigation
  • Validate HTML markup

Decision Tree

Interactive element? → Use <button> for actions (submit, toggle), <a> for navigation (page links).

Text content? → Use semantic elements: <article> for content, <section> for grouped content, <aside> for related info.

Form field? → Wrap in <label>, associate with htmlFor/id, use appropriate type attribute.

List of items? → Use <ul> for unordered, <ol> for ordered, <dl> for definition lists.

Heading? → Use <h1> through <h6> in sequential order, one <h1> per page.

Image? → Use <img> with descriptive alt text, or empty alt="" for decorative images.

Tabular data? → Use <table> with <thead>, <tbody>, <th>, <td>, and scope attributes.


Example

html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Page Title</title>
  </head>
  <body>
    <header>
      <nav aria-label="Main navigation">
        <ul>
          <li><a href="/">Home</a></li>
        </ul>
      </nav>
    </header>
    <main>
      <article>
        <h1>Article Title</h1>
        <p>Content</p>
      </article>
    </main>
  </body>
</html>

Edge Cases

Multiple h1 elements: HTML5 allows multiple <h1> tags, but screen readers work better with one per page.

Empty links: Avoid <a href="#"> without purpose. Use <button> for actions or provide proper href.

Div soup: Overuse of <div> harms semantics. Use semantic elements first, div as last resort.

Form without action: Forms should have action attribute or JavaScript handler. Omitting both causes page reload.

Button without type: Default type is submit. Always specify type="button" for non-submit buttons.


References