Skip to content

SEO 基础

Improve 搜索 rankings 使用 meta 标签, 语义 HTML, sitemaps, and structured 数据.

你将学到

  • 如何搜索 engines crawl, 索引, and rank web pages
  • 必要 meta 标签: title, 描述, 打开图, canonical
  • 如何语义 HTML and heading hierarchy signal 内容结构
  • Structured 数据 (Schema.org), sitemaps, and robots.txt for crawlers

概念讲解

SEO Basics

SEO (Search Engine Optimization) is the practice of making your web pages rank well in search engines like Google. Good SEO means when someone searches for what your page offers, they find it. SEO is part technical (how you structure your HTML and metadata), part content (what you write), and part authority (who links to you). This lesson covers the technical fundamentals every web developer must know.

How Search Engines Work

Search engines do three things: crawl (follow links to discover pages), index (store and understand the content), and rank (order results by relevance and quality). Your job is to make crawling easy, your content understandable, and your pages fast and accessible. If a search engine cannot crawl your page or understand its content, it cannot rank it — no matter how good the content is.

Essential Meta Tags

The <head> of your HTML carries metadata that search engines and social media read:

  • <title> — the most important on-page SEO signal. Unique, descriptive, under 60 characters.
  • <meta name="描述"> — the snippet shown in search results. Under 155 characters, compelling, unique per page.
  • <链接 rel="canonical"> — tells search engines the preferred URL when duplicate content exists.
  • Open Graph tags (og:title, og:描述, og:镜像) — control how your page looks when shared on social media.

Semantic HTML and Headings

Search engines use your HTML structure to understand content. Use one <h1> per page (the main topic), followed by <h2>s for sections, <h3>s for sub-sections — a logical, nested hierarchy. Use semantic tags (<article>, <nav>, <主要>) so the crawler can identify what is navigation vs. content. A page full of <div>s tells the search engine nothing about the content's structure.

Structured Data (Schema.org)

Structured data uses a vocabulary called Schema.org to tell search engines exactly what your content is — a recipe, a product, a review, an event. You add it as JSON-LD in a <script type="application/ld+json"> tag. This enables rich results in search — star ratings, prices, event dates shown directly in the search listing. It does not directly improve ranking, but it improves click-through rate by making your result more attractive.

Sitemaps and robots.txt

A sitemap.xml lists all your pages, helping search engines discover them. A robots.txt tells crawlers what they may and may not crawl. Submit your sitemap in Google Search Console. For large sites, a sitemap is essential; for small sites, good internal linking may suffice, but a sitemap never hurts.

示例代码

              <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>Chocolate Chip Cookie Recipe — Easy & Chewy</title>
    <meta name="description"
          content="Classic chocolate chip cookies in 30 minutes.
                   Chewy centers, crisp edges, no mixer needed." />
    <link rel="canonical" href="https://example.com/recipes/chocolate-chip-cookies" />

    <!-- Open Graph for social sharing -->
    <meta property="og:title" content="Chocolate Chip Cookie Recipe" />
    <meta property="og:image" content="https://example.com/img/cookies.jpg" />
    <meta property="og:type" content="article" />

    <!-- Structured data for rich results -->
    <script type="application/ld+json">
    {
      "@context": "https://schema.org",
      "@type": "Recipe",
      "name": "Chocolate Chip Cookies",
      "cookTime": "PT30M",
      "recipeYield": "24 cookies",
      "aggregateRating": {
        "@type": "AggregateRating",
        "ratingValue": "4.8",
        "reviewCount": "342"
      }
    }
    </script>
  </head>
  <body>
    <main>
      <article>
        <h1>Chocolate Chip Cookies</h1>
        <p>Classic, chewy, and ready in 30 minutes.</p>
      </article>
    </main>
  </body>
</html>
            

title and 描述是 唯一 and compelling. canonical prevents duplicate-内容 issues. 打开图 标签 control social sharing appearance. JSON-LD structured 数据 tells 搜索 engines 这个是 Recipe 使用 rating, 启用 rich results. h1 清晰地状态 page's 主题.

动手试一试

  • HTML ↔ Markdown

    检查那个你的 SEO-optimized HTML converts cleanly 到 Markdown for 内容 reuse.

  • Markdown Previewer

    Preview 你的内容到 验证 heading 结构 and readability for SEO.

常见错误

错误写法

Using 相同 <title> and meta 描述 on 每个 page.

正确做法

每个 page 需要唯一, descriptive title (under 60 chars) and meta 描述 (under 155 chars). title 是 strongest on-page SEO signal. Duplicate titles tell 搜索 engines 你的 pages 是相同.

错误写法

Using 多个 <h1> 标签 or skipping heading levels (h1 到 h3 使用否 h2).

正确做法

Use 精确地 one <h1> 每 page as 主要主题. Follow logical, nested hierarchy: h1 > h2 > h3. 做不 skip levels. 搜索 engines and screen readers 两者都 rely on 这个结构到 理解内容.

相关速查表

练习 SEO 基础

4 个练习

练习 SEO 基础

查阅不认识的术语

新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。

查看术语表

动手做项目

通过引导式项目应用所学,含起始代码与解决方案。

查看项目

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误