<article> - 第一篇文章
文章 in 容...这 is 一篇独立 , 完整 in 容.
LearningHTML语义化 concepts and 语义化元素 using
HTML语义化 is 指using适当 HTMLtag来表达 in 容 structure and 含义, 而不仅仅 is for 了展示效果. 语义化 HTMLcode更加清晰, 易于understanding and maintenance, 同时也 has 利于搜index擎optimization (SEO) and 无障碍访问.
<div id="header">
<h1>网站标题</h1>
</div>
<div id="nav">
<ul>
<li><a href="#">首页</a></li>
<li><a href="#">About Us</a></li>
</ul>
</div>
<div id="content">
<div class="article">
<h2>文章标题</h2>
<p>文章 in 容...</p>
</div>
</div>
<div id="footer">
<p>版权information</p>
</div>
<header>
<h1>网站标题</h1>
</header>
<nav>
<ul>
<li><a href="#">首页</a></li>
<li><a href="#">About Us</a></li>
</ul>
</nav>
<main>
<article>
<h2>文章标题</h2>
<p>文章 in 容...</p>
</article>
</main>
<footer>
<p>版权information</p>
</footer>
HTML5引入了一系列语义化元素, 使Development者able to更准确地describes页面structure:
| 元素 | describes |
|---|---|
| <header> | 定义页面 or 区域 头部, 通常package含标题, 标志 and 导航 |
| <nav> | 定义导航链接 containers |
| <main> | 定义页面 主要 in 容区域 |
| <section> | 定义documentationin 一个区块, 通常 has 标题 |
| <article> | 定义独立 , 完整 in 容, such as文章, 博客帖子etc. |
| <aside> | 定义侧edge栏 or and 主要 in 容相关但非core in 容 |
| <footer> | 定义页面 or 区域 底部, 通常package含版权information, 联系方式etc. |
| <figure> | 定义自package含 媒体 in 容, such asgraph像, graph表, codeetc. |
| <figcaption> | 定义figure元素 标题 or 说明 |
| <time> | 定义日期 or 时间 |
| <mark> | 定义需要标记 or highlight 文本 |
| <nav> | 定义导航链接 containers |
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>语义化HTMLstructure</title>
</head>
<body>
<!-- 页面头部 -->
<header>
<h1>网站标题</h1>
<!-- 导航 -->
<nav>
<ul>
<li><a href="#">首页</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</nav>
</header>
<!-- 主要 in 容 -->
<main>
<!-- 文章list区域 -->
<section>
<h2>最 new 文章</h2>
<!-- 第一篇文章 -->
<article>
<h3>文章标题1</h3>
<p>文章 in 容...</p>
<footer>
<p>release日期: <time datetime="2026-01-01">2026年1月1日</time></p>
</footer>
</article>
<!-- 第二篇文章 -->
<article>
<h3>文章标题2</h3>
<p>文章 in 容...</p>
<footer>
<p>release日期: <time datetime="2026-01-02">2026年1月2日</time></p>
</footer>
</article>
</section>
<!-- 侧edge栏 -->
<aside>
<h3>相关链接</h3>
<ul>
<li><a href="#">相关resource1</a></li>
<li><a href="#">相关resource2</a></li>
</ul>
</aside>
</main>
<!-- 页面底部 -->
<footer>
<p>© 2026 网站名称. All Rights Reserved.</p>
</footer>
</body>
</html>
package含网站标题 and 导航
文章 in 容...这 is 一篇独立 , 完整 in 容.
文章 in 容...这 is 另一篇独立 , 完整 in 容.
正确using标题tag (h1-h6) 来建立 in 容 层级structure:
<!-- 正确 标题层级 -->
<h1>网站标题</h1>
<h2>章节标题</h2>
<h3>子章节标题</h3>
<h4> small 节标题</h4>
<!-- error 标题层级 (跳过了h2) -->
<h1>网站标题</h1>
<h3>章节标题</h3>
using适当 文本语义tag来表达 in 容 含义:
<!-- 文本语义化example -->
<p>这 is 一段普通文本, 其inpackage含<strong> important in 容</strong> and <em>强调 in 容</em>. </p>
<p> in HTML5in, 我们应该using<code><section></code>tag来定义区块. </p>
<p>注意: <mark>这个部分需要特别注意</mark>. </p>
<p>release日期: <time datetime="2026-01-01">2026年1月1日</time></p>
usingfigure and figcaptiontag来 for 媒体 in 容添加语义:
<!-- 媒体 in 容语义化example -->
<figure>
<img src="image.jpg" alt="examplegraph像">
<figcaption>graph1: examplegraph像 说明文字</figcaption>
</figure>
<figure>
<pre><code>function hello() {
console.log('Hello, world!');
}</code></pre>
<figcaption>codeexample: simple JavaScriptfunction</figcaption>
</figure>
creation一个语义化 博客页面, package含以 under in 容:
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>我 博客</title>
<style>
/* simple 样式 */
body {
font-family: Arial, sans-serif;
line-height: 1.6;
margin: 0;
padding: 0;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 0 20px;
}
header {
background-color: #333;
color: white;
padding: 20px 0;
}
nav ul {
list-style: none;
padding: 0;
display: flex;
}
nav ul li {
margin-right: 20px;
}
nav ul li a {
color: white;
text-decoration: none;
}
main {
display: flex;
gap: 20px;
margin: 20px 0;
}
article {
flex: 3;
background-color: #f9f9f9;
padding: 20px;
border-radius: 5px;
}
aside {
flex: 1;
background-color: #f0f0f0;
padding: 20px;
border-radius: 5px;
}
footer {
background-color: #333;
color: white;
text-align: center;
padding: 20px 0;
margin-top: 20px;
}
figure {
margin: 20px 0;
}
figure img {
max-width: 100%;
height: auto;
}
figcaption {
text-align: center;
font-style: italic;
margin-top: 10px;
}
@media (max-width: 768px) {
main {
flex-direction: column;
}
}
</style>
</head>
<body>
<header>
我 techniques博客
</header>
<main>
<article>
HTML语义化 important 性
HTML语义化 is 现代网页Developmentin important concepts, 它不仅影响code readable 性 and 可maintenance性, 还 for 搜index擎optimization and 无障碍访问 has 着 important 影响.
what is HTML语义化?
HTML语义化 is 指using适当 HTMLtag来表达 in 容 structure and 含义, 而不仅仅 is for 了展示效果. 例such as, using<nav>tag来定义导航栏, using<article>tag来定义文章 in 容etc..
graph1: HTML语义化页面structure示意graph
语义化 优势
- improvingcode readable 性: 语义化tag使codestructure更加清晰, 易于understanding and maintenance
- 改善SEO: 搜index擎able to更 good 地understanding页面 in 容, improving搜索排名
- 增强可访问性: 屏幕阅读器etc.辅助techniquesable to更 good 地解读页面structure
- 简化样式 and 脚本: 语义化tag for CSS and JavaScriptproviding了更清晰 hook
such as何implementation语义化?
implementationHTML语义化 关键 is 选择合适 tag来表达 in 容 含义:
- usingHTML5语义化tag (header, nav, main, section, article, aside, footeretc.)
- 正确using标题层级 (h1-h6)
- using适当 文本语义tag (strong, em, code, marketc.)
- for 媒体 in 容usingfigure and figcaptiontag
- 避免过度usingdiv and spantag
</article>
<aside>
相关链接
最 new 文章
关于我
我 is 一名 before 端Development工程师, 热爱分享techniquesknowledge and Developmentexperience.
</aside>
</main>
<footer>
© 2026 我 techniques博客. All Rights Reserved.
</footer>
</body>
</html>
using适当 表单语义tag来improving表单 可访问性:
<!-- 表单语义化example -->
<form action="submit.php" method="post">
<fieldset>
<legend>个人information</legend>
<div>
<label for="name">姓名: </label>
<input type="text" id="name" name="name" required>
</div>
<div>
<label for="email">电子email: </label>
<input type="email" id="email" name="email" required>
</div>
</fieldset>
<button type="submit">submitting</button>
</form>
HTML5.1 and HTML5.2引入了一些 new 语义化元素 and features, 进一步增强了HTML 语义表达capacity:
<dialog>: 定义 for 话框 or 模态窗口<picture>: for 不同设备providing不同 graph像sources<source>: and picture, audio, videoetc.元素配合using, providing不同 媒体sources<track>: for 视频 or 音频添加字幕 or describes轨道in 现代 before 端framework (such asReact, Vue, Angular) in, 语义化仍然非常 important :
// Reactin 语义化example
function BlogPost() {
return (
<article> {/* using语义化tag */}
<header>
<h2>文章标题</h2>
<p>release日期: <time datetime="2026-01-01">2026年1月1日</time></p>
</header>
<main>
<p>文章 in 容...</p>
</main>
<footer>
<p>作者: 张三</p>
</footer>
</article>
);
}
语义化HTML is implementation无障碍访问 Basics, 它使得屏幕阅读器etc.辅助techniquesable to更 good 地understanding页面structure and in 容: