HTML - <article> 標籤



HTML <article> 標籤用於在 HTML 文件中表示獨立的、自包含的組合內容。此標籤包含在 HTML5 中。

單個 HTML 文件可以包含多個 article 元素。當 HTML <article> 元素巢狀時,內部元素表示與外部元素相關的文章。例如,社交媒體帖子上的評論可以是 article 元素,巢狀在表示社交媒體帖子的 article 元素中。它主要用於論壇帖子、雜誌或報紙文章、部落格文章、產品卡片等。

語法

<article>
   .....
</article>

屬性

HTML article 標籤支援 HTML 的全域性事件屬性。

HTML article 標籤示例

以下示例將說明 article 標籤的使用方法、使用時機和如何使用 article 標籤建立 article 元素。

使用 article 標籤建立自包含內容

在以下示例中,我們使用 <article> 標籤建立了兩個自包含的內容,它們彼此獨立,也獨立於父元素。

<!DOCTYPE html>
<html lang="en">

<head>
   <title>HTML article tag</title>
</head>

<body>
   <!-- Creating article Element -->
   <h2>HTML 'article' Element</h2>
   <article>
      <h3>HTML Tags</h3>
      <p>
          HTML tags are similar to keywords, which specify 
          how a web browser will format and display content.
          A web browser can differentiate between simple content 
          and HTML content with the use of tags. 
      </p>
   </article>
   <article>
      <h3>HTML Attributes</h3>
      <p>
          An attribute is used to define the characteristics
          of an HTML element and is placed inside the element's 
          opening tag. All attributes are made up of two parts:
          a name and a value
      </p>
   </article>
</body>

</html>

article 元素的樣式

考慮以下示例,我們將使用 <article> 標籤並應用 CSS 屬性。

<!DOCTYPE html>
<html lang="en">
<head>
   <title>HTML article tag</title>
   <style>
      article {
         width: 300px;
         height: 150px;
         background-color: aquamarine;
         border-radius: 10px;
      }
      article h3,
      p {
         margin: 10px 10px;
      }
   </style>
</head>
<body>
   <!--create a article element-->
   <h2>HTML 'article' Element</h2>
   <article>
      <h3>HTML Tags</h3>
      <p>
          HTML tags are similar to keywords, which specify 
          how a web browser will format and display content.
          A web browser can differentiate between simple content 
          and HTML content with the use of tags. 
      </p>
   </article>
   <article>
      <h3>HTML Attributes</h3>
      <p>
          An attribute is used to define the characteristics
          of an HTML element and is placed inside the element's 
          opening tag. All attributes are made up of two parts:
          a name and a value
      </p>
   </article>
</body>
</html>

巢狀的 article 元素

讓我們來看看另一種情況,我們將建立一個巢狀的 article 元素。

<!DOCTYPE html>
<html lang="en">
<head>
   <title>HTML article Tag</title>
   <style>
      article {
         margin: 5px;
         border-radius: 10px;
         padding: 10px;
         border: 2px solid black;
      }
      p {
         margin: 10px;
      }
   </style>
</head>
<body>
   <!--create a article element-->
   <h2>HTML 'article' Element</h2>
   <article>
   <h3>HTML Elements</h3>
   <p>
       HTML Elements are building block of a web page.
       It is used to create component for webpages.
   </p>
   <article>
      <h3>HTML Tags</h3>
      <p>
          HTML tags are similar to keywords, which specify 
          how a web browser will format and display content.
          A web browser can differentiate between simple content 
          and HTML content with the use of tags. 
      </p>
   </article>
   <article>
      <h3>HTML Attributes</h3>
      <p>
          An attribute is used to define the characteristics
          of an HTML element and is placed inside the element's 
          opening tag. All attributes are made up of two parts:
          a name and a value
      </p>
   </article>
   </article>
</body>
</html>

在 article 元素中實現影像

在以下示例中,我們建立巢狀的“article”元素,以使用 <article> 標籤表示部落格文章及其評論的自包含內容。

<!DOCTYPE html>
<html lang="en">
<head>
   <title>HTML article tag</title>
   <style>
      article img {
         width: 200px;
      }
   </style>
</head>
<body>
   <!--create a article element-->
   <article>
      <h2>Blog post</h2>
      <img src="/images/logo.png?v3" alt="Tutorialspoint logo">
      <article>
      <h2>Comments</h2>
      <p>Dman good...</p>
      <p>fabulous...!</p>
      </article>
   </article>
</body>
</html>

支援的瀏覽器

標籤 Chrome Edge Firefox Safari Opera
aside 是 6.0 是 9.0 是 4.0 是 5.0 是 11.1
html_tags_reference.htm
廣告