Search code examples
htmlsemantic-markup

html figure element: can figcaption be placed before img


Is it semantically/syntactically correct to have the figcaption element be positioned anywhere within the figure element?

Consider the following:

<figure>
  <figcaption>Hello caption</figcaption>
  <img src="/path/to/file">
</figure>

Solution

  • tl;dr:

    • W3C: figcaption can be placed anywhere in figure (as child, not descendant)
    • WHATWG: figcaption can be placed as first or as last child of figure

    W3C

    In HTML5, the figcaption element has to be the first or the last child of figure:

    Either: One figcaption element followed by flow content.
    Or: Flow content followed by one figcaption element.
    Or: Flow content.

    In HTML 5.1, the figcaption element can be placed anywhere in the figure element:

    Flow content optionally including a figcaption child element.

    In HTML 5.1 2nd Edition, too.

    In HTML 5.2 (Proposed REC), too.

    Here’s the issue about the change:
    Allow figcaption anywhere in a figure element?

    WHATWG

    In the HTML Living Standard (as of 2017-11-17), it’s the same as in HTML5:

    Either: One figcaption element followed by flow content.
    Or: Flow content followed by one figcaption element.
    Or: Flow content.