HTML - <article> Tag



The HTML <article> tag is used to represent an indepenedent, self-contained composition content in an HTML document.

When an HTML <article> element is nested, the inner element represents the article related to the outer element. For example, comments on social media posts can be an article element nested in the article representing the social media post.

It is mostly used for forum posts, magazine or newspaper articles, blog entries, product cards, etc.

A single HTML document can have multiple article elements.

Syntax

Following is the syntax of the <article> tag −

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

Example

The following program shows the usage of the HTML <article> tag.

<!DOCTYPE html>
<html lang="en">
<head>
   <title>HTML article tag</title>
</head>
<body>
   <!--create a article element-->
   <p>Example of the HTML 'article' element</p>
   <article>
      <h2>List of frontend technologies:-</h2>
      <ul>
      <li>HTML</li>
      <li>CSS</li>
      <li>JavaScript</li>
      <li>Angular</li>
      <li>React</li>
      <li>Bootstarp</li>
      </ul>
   </article>
</body>
</html>

When we run the above code, it will generate an output consisting of the text displayed on the webpage.

Example

Consider the following example, where we are going to use the <article> tag and applying the CSS properties.

<!DOCTYPE html>
<html lang="en">
<head>
   <title>HTML article tag</title>
   <style>
      article {
         width: 300px;
         height: 150px;
         background-color: aquamarine;
         border-radius: 10px;
      }
      article h2,
      p {
         margin: 10px 10px;
      }
   </style>
</head>
<body>
   <!--create a article element-->
   <p>Example of the HTML 'article' element</p>
   <article>
      <h2>HTML</h2>
      <p>HTML stands for 'Hyper Text Markup Language'.</p>
      <h2>CSS</h2>
      <p>CSS stands for 'Cascading Style Sheet'.</p>
   </article>
</body>
</html>

On running the above code, the output window will pop up, consisting of the text along with a CSS applied to it is displayed on the webpage.

Example

Let's look into the another scenario, where we are going to create a nested article element.

<!DOCTYPE html>
<html lang="en">
<head>
   <title>HTML article tag</title>
   <style>
      .demo {
         width: 250px;
         height: 270px;
         border-radius: 8px;
         background-color: aquamarine;
         margin: none;
      }

      article {
         background-color: aqua;
         width: 80%;
         margin: auto;
         border-radius: 10px;
      }

      article h2,
      p {
         margin: 10px 10px;
      }
   </style>
</head>
<body>
   <!--create a article element-->
   <p>Example of the HTML 'article' element</p>
   <article class="demo">
      <h1>Frontend technologies:- </h1>
      <article>
      <h2>HTML</h2>
      <p>Hyper Text Markup Language</p>
      </article>
      <article>
      <h2>CSS</h2>
      <p>Cascading Style Sheet</p>
      </article>
      <article>
      <h2>JS</h2>
      <p>JavaScript</p>
      </article>
   </article>
</body>
</html>

When we run the above code, it will generate an output displaying the nested article text on the webpage.

Example

In the following example, we are creating nested ‘article’ elements to represent the self-contained content of the blog post and its comments using <article> tag.

<!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="https://www.tutorialspoint.com/static/images/logo.png?v3" alt="">
      <article>
      <h2>Comments</h2>
      <p>Dman good...</p>
      <p>fabulous...!</p>
      </article>
   </article>
</body>
</html>

When we run the above code, it will generate an output displaying the text on the webpage.

html_tags_reference.htm
Advertisements