HTML - <figure> Tag



Self-contained content can be identified using the <figure> tag. The tag may include diagrams, images, code examples, and so on. The content of the <figure> tag is connected to the content of the main flow. It is viewed as a standalone unit, though.

The <figcaption> tag is used to give a caption or explanation to the content of the <figure> tag. The <figcaption> tag is positioned as the first or last child element of the <figure> tag. The content will appear at the top of the image if <figcaption> is the first nested element.

Syntax

Following is the syntax of the <figure> tag −

<figure>
   Image content...
</figure>

Example

In the following we are going to use the HTML <figure> tag .

<!DOCTYPE html>
<html>
<body>
   <p>Tutorials Point originated from the idea that there exists a class of readers who respond better to online content and prefer to learn new skills at their own pace from the comforts of their drawing rooms. The journey commenced with a single tutorial on HTML in 2006 and elated by the response it generated, we worked our way to adding fresh tutorials to our repository which now proudly flaunts a wealth of tutorials and allied articles on topics ranging from programming languages to web designing to academics and much more.</p>
   <figure>
      <img src="https://www.tutorialspoint.com/cg/images/logo.png" alt="LOGO" />
   </figure>
</body>
</html>

On running the above code, the output window will pop up, displaying the image along with text on top of the image displayed on the webpage.

Example

Considering the following example, we are going to add the additional alert to our webpage while using the <figure> tag.

<!DOCTYPE html>
<html>
<body style="background-color:#D5F5E3">
   <figure>
      <img src="https://www.tutorialspoint.com/cg/images/logo.png" alt="computer image" style="width:50%">
      <figcaption>
         <marquee>The Best E-Way Learning</marquee>
      </figcaption>
      <br>
      <button type="buttton" onclick="alert('WELCOME.!')">Click The Button </button>
   </figure>
</body>
</html>

When we execute the above code, it will generate the output consisting of the image along with a text button uploaded on the webpage. When the user clicks the button, the event gets triggered and displays the alert message on the screen.

Example

Let’s look at the following example, where we are going to observe the difference between the <div> tag and the <figure> tag.

<!DOCTYPE html>
<html>
<body style="background-color:#D5F5E3">
   <p>Using div:</p>
   <div>
      <img src="https://www.tutorialspoint.com/cg/images/logo.png" alt="logo">
      <p> TutorialsPoint Logo. </p>
   </div>
   <br>
   <br>
   <br>
   <p>using figure:</p>
   <figure>
      <img src="https://www.tutorialspoint.com/cg/images/logo.png" alt="Logo">
      <figcaption>TutorialsPoint Logo</figcaption>
   </figure>
</body>
</html>

On running the above code, it will generate an output consisting of both the image and the text used with the <div> and <figure> tags that were uploaded on the webpage.

html_tags_reference.htm
Advertisements