basics of website design banner photo

HTML

HTML 5

CSS 2.1

CSS 3

Reference

HTML5 <figure> and <figcaption> Elements.

The <figure> element specifies content (figures) that is self-contained such as a photo, illustration, diagram or code-listing. This content is related to the flow of the main document but could be removed from the document and placed in an appendix or reference section without altering the flow of the main body of the document.

The <figcaption> element provides a caption for the content contained by the <figure> element and if not set then the content in the <figure> element has no caption.

The <figcaption> element is always a child of the <figure> element although it can be placed before or after the main content and a <figure> element cannot have more than one <figcaption> child.

Examples of <figure> and <figcaption> in use.

Here are two examples of the <figure> element using a photo and adding a caption with <figcaption>. They are totally unstyled, which you can change as you wish, but illustrate how browsers respond to these two elements. The placement of <figcaption> in the code before or after the <img> element dictates whether the caption is displayed above or below the image.

Using <figcaption> before the content.

Code:

<figure>
<figcaption>Example with the caption before the image<figcaption/>
<img src="figexample.jpg"
<figure/>

Result:

Example with the caption before the image
random photo to illustrate the figure element in use

Using <figcaption> after the content.

Code:

<figure>
<img src="figexample.jpg"
<figcaption>Example with the caption after the image<figcaption/>
<figure/>

Result:

example photo showing the figure element in use
Example with the caption after the image

NOTE: Versions of Internet Explorer before IE9 do not support this element and the caption is positioned to the side of the content instead of above or below.

<figure> Attributes

<figcaption> Attributes

New HTML5 Elements