The <figure> and <figcaption> tags are introduced in HTML5 to semantically represent self-contained content along with its caption. They are commonly used to group media elements like images, illustrations, diagrams, code snippets, etc., with their corresponding captions, enhancing the document's structure and accessibility.
Below is an example of how to use the <figure> and <figcaption> tags:
<figure>
<img src="https://www.plus2net.com/images/top2.jpg" alt="Sample Image">
<figcaption>Fig.1 - A sample placeholder image.</figcaption>
</figure>
You can enhance the appearance of the <figure> and <figcaption> elements using CSS. Here's an example of how to style these elements:
figure {
border: 1px solid #ccc;
padding: 10px;
max-width: 600px;
margin: 20px auto;
text-align: center;
}
figcaption {
background-color: #f8f8f8;
color: #555;
font-style: italic;
padding: 5px;
margin-top: 10px;
}
img {
max-width: 100%;
height: auto;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Figure and Figcaption Example</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
figure {
border: 1px solid #ccc;
padding: 10px;
max-width: 300px;
margin: auto;
text-align: center;
}
figcaption {
background-color: #f8f8f8;
color: #555;
font-style: italic;
padding: 5px;
margin-top: 10px;
}
</style>
</head>
<body>
<figure>
<img src="https://www.plus2net.com/images/top2.jpg" alt="Sample Image">
<figcaption>Fig.1 - A sample placeholder image.</figcaption>
</figure>
</body>
</html>
Utilizing the <figure> and <figcaption> tags can positively impact SEO by providing search engines with explicit context about media content. This semantic clarity can lead to better indexing and visibility in search results.
The <figure> and <figcaption> tags are valuable additions in HTML5 for semantically organizing media content with captions. Their proper use enhances accessibility, SEO, and overall user experience by clearly associating visual or media elements with their descriptions.
HTML5 Tags Types of HTML tags