HTML <main> 标签

HTML <main> 标签是一个语义化标签,用于定义文档的主要内容。主要内容包含页面旨在向用户提供的主要信息或功能。例如,

<body>
    <header>Programiz</header>
    <main>
        <p>Learn HTML with us.</p>
    </main>
</body>

浏览器输出

Sample article with the main tag

通常,<main> 标签不应包含文章的辅助部分,如导航链接、侧边栏、版权声明、徽标等。主要内容应是 HTML 文档中独一无二的。


示例:HTML <main>

<main>
    <h1>HTML Tutorial</h1>
    <p>Welcome to our HTML tutorial! In this tutorial, you will learn the basics of HTML and how to use it to create
        your own web pages.</p>

    <h2>Chapter 1: Introduction to HTML</h2>
    <article>
        <h3>What is HTML?</h3>
        <p>HTML (Hypertext Markup Language) is a markup language used to structure and format content on the web. It
            uses a system of tags to define the different elements of a web page, such as headings, paragraphs, and
            links.</p>
    </article>
    <h2>Chapter 2: Getting Started with HTML</h2>
    <article>
        <h3>Creating an HTML Document</h3>
        <p>To create an HTML document, you will need a text editor and a web browser. You can use a simple text editor
            like Notepad on Windows, or TextEdit on Mac. Once you have a text editor, you can create a new HTML document
            by saving a file with the ".html" extension.</p>
    </article>
</main>

浏览器输出

Sample article with the main tag

我们的高级学习平台,凭借十多年的经验和数千条反馈创建。

以前所未有的方式学习和提高您的编程技能。

试用 Programiz PRO
  • 交互式课程
  • 证书
  • AI 帮助
  • 2000+ 挑战