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