Outline
什么是 HTML
HTML(HyperText Markup Language,超文本标记语言)是用来创建网页的标准标记语言。
HTML 文档结构
基本文档模板
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>页面标题</title>
</head>
<body>
<!-- 页面内容 -->
</body>
</html>
文档类型声明
根元素
头部区域 (head)
<head>
<!-- 元数据:不会显示在页面中 -->
<meta charset="UTF-8"> <!-- 字符编码 -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>文档标题</title>
<link rel="stylesheet" href="styles.css">
</head>
主体区域 (body)
常用标签及用法
文本标签
标题标签
段落和文本格式
<p>这是一个段落。</p>
<!-- 文本格式化 -->
<strong>加粗(重要)</strong>
<em>斜体(强调)</em>
<mark>标记文本</mark>
<small>小号文本</small>
<del>删除的文本</del>
<ins>插入的文本</ins>
<!-- 预格式化文本 -->
<pre>
保留空格
和换行
</pre>
<code>代码片段</code>
链接和图片
超链接
<!-- 外部链接 -->
<a href="https://example.com" target="_blank">访问示例网站</a>
<!-- 内部链接 -->
<a href="about.html">关于我们</a>
<!-- 锚点链接 -->
<a href="#section1">跳转到第一节</a>
图片
列表
无序列表
有序列表
表格
基础表格
<table border="1">
<tr>
<th>姓名</th>
<th>年龄</th>
<th>城市</th>
</tr>
<tr>
<td>张三</td>
<td>25</td>
<td>北京</td>
</tr>
<tr>
<td>李四</td>
<td>30</td>
<td>上海</td>
</tr>
</table>
表单与输入
基础表单结构
<form action="/submit" method="POST">
<!-- 表单控件 -->
<input type="text" name="username" required>
<button type="submit">提交</button>
</form>
输入类型
<!-- 文本输入 -->
<input type="text" placeholder="请输入文本">
<!-- 密码输入 -->
<input type="password" placeholder="密码">
<!-- 邮箱输入 -->
<input type="email" placeholder="邮箱地址">
<!-- 数字输入 -->
<input type="number" min="1" max="100">
<!-- 日期选择 -->
<input type="date">
<!-- 文件上传 -->
<input type="file">
<!-- 单选按钮 -->
<input type="radio" name="gender" value="male" id="male">
<label for="male">男</label>
<!-- 复选框 -->
<input type="checkbox" name="hobby" value="reading" id="reading">
<label for="reading">阅读</label>