Using HTML5 figures in today’s browsers

[2011-04-01] dev, html5
(Ad, please don’t block)
HTML5 includes tags for figures and figure captions. This post explains how to use them in modern browsers.

The following code can be used in HTML5 to display figures:
    <figure>
        <img src="image.jpg">
        <figcaption>This is the caption.</figcaption>
    </figure>
With the following CSS, the above code works in many modern browsers (tested in Firefox, Chrome, Safari).
    figure {
        display: table;
        text-align: center;
        /* optional: border */
        border: thin solid gray;
        padding: 5px;
    }
    figcaption {
        display: block;
    }
Unfortunately, this might not work in some older browsers. You can experiment by replacing display:table with display:block (for figure), but then the border will fill the complete width of the page.