Accessible HTML Page
你将构建什么
accessible HTML page 使用请求头, nav, 主要内容 (heading, paragraph, 镜像使用 alt, and labeled 表单字段), and footer — 所有 using 语义元素 and ARIA 哪里需要.
学习目标
- Use 语义 HTML5 landmarks (请求头, nav, 主要, footer)
- 添加 alt 文本到 镜像 for screen readers
- Associate labels 使用表单输入 using for/id
- Use proper heading hierarchy (h1 → h2 → h3)
前置要求
- HTML document 结构
- 基础理解的 语义 HTML 标签
步骤
- 1
设置语义 skeleton
创建 accessible.HTML 使用 landmark 元素: 请求头, nav, 主要, and footer.
代码<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Accessible Page</title> </head> <body> <header></header> <nav></nav> <main></main> <footer></footer> </body> </html>预期结果
空 page 使用 four landmark 元素 in 位置.
- 2
Fill 请求头 and nav
添加 h1 site title in 请求头 and nav 列表使用 3 链接. h1 是主要 heading — 那里应该是 仅 one 每 page.
代码<header> <h1>My Accessible Site</h1> </header> <nav> <ul> <li><a href="#home">Home</a></li> <li><a href="#about">About</a></li> <li><a href="#contact">Contact</a></li> </ul> </nav>预期结果
请求头 shows site title and nav shows 3 链接.
- 3
添加主要内容使用镜像 and 表单
In 主要, 添加 h2, paragraph, 镜像使用 descriptive alt 文本, and labeled 搜索输入.
代码<main> <h2>Welcome</h2> <p>This page is built with accessibility in mind.</p> <img src="https://placehold.co/400x200" alt="A placeholder showing a 400 by 200 pixel image"> <form> <label for="search">Search the site</label> <input type="search" id="search" name="search"> <button type="submit">Search</button> </form> </main>预期结果
主要区域 shows heading, paragraph, 镜像, and 搜索表单.
提示
alt 文本应该描述什么镜像 shows, 不只是 '镜像'.
- 4
添加 footer and minimal CSS
添加 footer 使用 copyright 行. 添加小 样式块 for 基础 readability.
代码<footer> <p>© 2026 My Accessible Site</p> </footer> <style> body { font-family: system-ui, sans-serif; max-width: 40rem; margin: 0 auto; padding: 1rem; } nav ul { list-style: none; display: flex; gap: 1rem; padding: 0; } img { max-width: 100%; height: auto; } </style>预期结果
polished, accessible page 使用所有 landmarks, proper labels, and alt 文本.
- 5
添加响应式样式
使用媒体查询为移动端调整布局:在小屏幕上将多列改为单列、缩小字号、调整间距。移动优先意味着小屏幕体验同样重要。
代码@media (max-width: 640px) { .container { flex-direction: column; padding: 1rem; } h1 { font-size: 1.5rem; } .card { width: 100%; margin-bottom: 1rem; } }预期结果
在 640px 以下视口,布局变为单列,字号和间距缩小,内容不溢出。
自己动手试试
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Accessible Page</title>
</head>
<body>
<!-- TODO: header, nav, main, footer -->
</body>
</html><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Accessible Page</title>
<style>
body { font-family: system-ui, sans-serif; max-width: 40rem; margin: 0 auto; padding: 1rem; }
nav ul { list-style: none; display: flex; gap: 1rem; padding: 0; }
img { max-width: 100%; height: auto; }
</style>
</head>
<body>
<header>
<h1>My Accessible Site</h1>
</header>
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
<main>
<h2>Welcome</h2>
<p>This page is built with accessibility in mind.</p>
<img src="https://placehold.co/400x200" alt="A placeholder showing a 400 by 200 pixel image">
<form>
<label for="search">Search the site</label>
<input type="search" id="search" name="search">
<button type="submit">Search</button>
</form>
</main>
<footer>
<p>© 2026 My Accessible Site</p>
</footer>
</body>
</html>你学到了什么
你构建 accessible page 使用语义 landmarks, proper heading hierarchy, descriptive alt 文本, and associated labels — 基础的 web accessibility 那个 benefits 所有用户.
相关资源
相关课程
- HTML Accessibility
Accessibility 最佳实践.
- HTML 语义标签
语义 landmark 元素.
相关练习
- Accessibility: alt 文本
练习 accessibility 概念.
- Label 关联测验
练习 label-输入关联.
相关速查表
- HTML Cheatsheet
语义元素引用.
相关错误
- Broken 镜像
镜像 accessibility issues.
相关术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
相关错误
用大白话解释常见错误——什么意思、为什么发生、如何修复。
- Broken 镜像
镜像 accessibility issues.