SHARE
Facebook X Pinterest WhatsApp

Using the Figure and Figcaption Markup Elements in Your HTML5 App

Written By
thumbnail
Vipul Patel
Vipul Patel
Nov 7, 2013

11/6/13

Introduction

Certain content on a web page is such that it is self-contained and can be moved away from the main flow of the document without changing the meaning of the document. Prior to HTML5, there was no markup support for such constructs. However, things change with HTML5. The HTML5 specification introduces first class support to represent a self-contained unit of content through the figure markup element.

The HTML5 specification says…

The HTML5 specification defines the figure markup element http://dev.w3.org/html5/markup/figure.html as….

The figure element represents a unit of content, optionally with a caption, that is self-contained, that is typically referenced as a single unit from the main flow of the document, and that can be moved away from the main flow of the document without affecting the document’s meaning.

 

The figure markup element is a type of flow element and requires a start as well as an end tag.

The id attribute of a figure markup element represents an identifier by which the figure is referenced in the web document.

The caption or legend of a figure markup element is represented using the figcaption markup element.  Note that the figcaption markup element is optional. It can be the first or the last child of a figure element. Like the figure markup element, the figcaption element must have both a start and an end tag.

The figure markup element has the following default attributes:

·         display : block

·         margin-before: 1em

·         margin-after: 1pm

·         margin-start: 40 px

·         margin-end: 40 px

The figcaption markup element has only the display (value of block) as default attribute.

The figure element is part of the surrounding flow.

 

 

Hands-On

We will build a simple web page which demonstrates use of figure and figcaption markup elements.

Our web page has two logical section – the first one only uses the figure markup element and the second uses both figure as well as figcaption.

<!DOCTYPE html>

<html>

<meta charset=”utf-8″>

<title>Figure and figcaption markup element sample</title>

<body>

    <header>

        <h1>Figure and figcaption markup element sample</h1>

        <h2>Example 1 – Winter</h2>

        <p>Demo showing figure markup element</p>

        <figure id=”1″>

 

            <img src=”http://www.desktopwallpaperhd.net/wallpapers/10/c/christmas-wallpapers-winter-jieri-white-holiday-107228.jpg” width=”50%” height=”50%“>

        </figure>

        <h2>Example 2 – summer</h2>

        <p>Demo showing figure and figcaption markup element</p>

        <figure id=”2″>

            <figcaption>Summer time.</figcaption>

            <img src=”http://wallzonehd.com/wp-content/uploads/2013/04/Summer-Sunset-Wallpaper.jpg” width=”50%” height=”50%“>

        </figure>

    </header>

    <footer>

        <p>HTML Goodies</p>

    </footer>

</body>

</html>

 

When the above listed web page is displayed in a modern browser, you will notice that the winter section does not have the caption to the figure section, while the summer section has it.

The code listed above is available for download at <download link>.

 

Summary

In this article, we learned about the figure and figcaption markup element. I hope you have found this information useful.

About the author

Vipul Patel is a Program Manager currently working at Amazon Corporation. He has formerly worked at Microsoft in the Lync team and in the .NET team (in the Base Class libraries and the Debugging and Profiling team). He can be reached at vipul.patel@hotmail.com

Recommended for you...

Best VR Game Development Platforms
Enrique Corrales
Jul 21, 2022
Best Online Courses to Learn HTML
Ronnie Payne
Jul 7, 2022
Working with HTML Images
Octavia Anghel
Jun 30, 2022
Web 3.0 and the Future Of Web Development
Rob Gravelle
Jun 23, 2022
HTML Goodies Logo

The original home of HTML tutorials. HTMLGoodies is a website dedicated to publishing tutorials that cover every aspect of being a web developer. We cover programming and web development tutorials on languages and technologies such as HTML, JavaScript, and CSS. In addition, our articles cover web frameworks like Angular and React.JS, as well as popular Content Management Systems (CMS) that include WordPress, Drupal, and Joomla. Website development platforms like Shopify, Squarespace, and Wix are also featured. Topics related to solid web design and Internet Marketing also find a home on HTMLGoodies, as we discuss UX/UI Design, Search Engine Optimization (SEO), and web dev best practices.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.