HTML
学习 HTML — markup language 那个 gives 每个 web page 它的结构 and 内容.
你将学到
- 什么 HTML 是 and 什么标签做
- 结构的 HTML document
- 常见标签: headings, paragraphs, 列表, 链接, 镜像
- 如何 attributes 添加 extra 信息到 元素
概念讲解
HTML
HTML (HyperText Markup Language) is the language that describes the structure and content of a web page. It is not a programming language — it does not loop or branch. It is a *markup* language: you wrap text in tags to say "this is a heading," "this is a paragraph," "this is a link."
Tags and Elements
tag 是一种 keyword wrapped in angle brackets. Most tags come in pairs — an opening and a closing tag — and the content between them is the element:
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
Some tags are self-closing — they have no content inside, like images:
<img src="photo.jpg" alt=" cat" />
Document Structure
Every HTML document follows the same skeleton:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<!-- visible content goes here -->
</body>
</html>
The <head> holds metadata (title, character encoding, linked stylesheets). The <请求体> holds everything the user sees.
Attributes
Attributes go inside the opening tag and add extra information. A link needs a destination (href); an image needs a source (src) and alternative text (alt):
<a href="https://example.com">Visit Example</a>
<img src="logo.png" alt="Company logo" />
Semantic HTML
Modern HTML favors semantic tags that describe meaning, not just appearance: <请求头>, <nav>, <主要>, <article>, <footer>. These help screen readers and search engines understand your page's structure.
示例代码
<!DOCTYPE html>
<html lang="en">
<body>
<header>
<h1>Recipe Book</h1>
<nav>
<a href="/">Home</a>
<a href="/recipes">Recipes</a>
</nav>
</header>
<main>
<article>
<h2>Chocolate Chip Cookies</h2>
<p>Prep time: <strong>15 minutes</strong></p>
<ul>
<li>2 cups flour</li>
<li>1 cup sugar</li>
<li>1 cup chocolate chips</li>
</ul>
<img src="cookies.jpg" alt="Fresh baked cookies" />
</article>
</main>
<footer>© 2024 Recipe Book</footer>
</body>
</html>
语义标签 (请求头, nav, 主要, article, footer) 描述 page's 结构. ul/li 列表持有 ingredients; img 需要 alt for accessibility.
动手试一试
- HTML Entity Encoder
Encode 特殊 characters 如 < and > 所以它们 display as 文本相反的 是 parsed as HTML.
- HTML ↔ Markdown
Convert HTML 到 Markdown and 后面 — see 如何结构映射之间格式.
常见错误
错误写法
Forgetting 到关闭标签 or nesting 它们不正确地.
正确做法
每个打开标签需要关闭标签, and 标签必须 nest properly: <p><strong>文本</strong></p>, 不 <p><strong>文本</p></strong>. Use HTML validator 到 catch mismatches.
错误写法
Omitting alt attribute on 镜像.
正确做法
总是包含 alt 文本. 它是 读取通过 screen readers and shown 当镜像失败到 加载. Use 空 alt (alt='') 仅 for purely decorative 镜像.
相关资源
相关代码片段
- HTML 表单 Snippet
ready-到-use 表单使用所有常见输入类型.
- HTML 表 Snippet
Structured 表 markup 使用请求头 and 行.
相关速查表
- HTML Cheatsheet
完整引用 for HTML 标签 and attributes.
练习 HTML
7 个练习
查阅不认识的术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
动手做项目
通过引导式项目应用所学,含起始代码与解决方案。
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。