Images & Media
HTML <picture> element
Groups alternative image sources for art direction or format selection. The required img child provides the displayed image element and fallback source. The example uses illustrative local asset paths; supply matching files before running it. The browser tests source conditions in order and uses the img fallback as the actual displayed image. Use alt on img rather than source. Distinguish art direction from resolution selection using srcset alone. It accepts global HTML attributes; individual global features may be inapplicable or restricted.
Formal Syntax & Structure
html syntaxhtml
<picture> <source srcset="wide.jpg" media="(min-width: 800px)"> <img src="small.jpg" alt="Description"></picture>Return Value
HTMLPictureElement
Content model: Zero or more source elements followed by one img; script-supporting elements may be interspersed.
Working Example
Example Snippethtml
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <title>HTML example</title> </head> <body> <picture> <source media="(min-width: 800px)" srcset="garden-wide.jpg"> <img src="garden.jpg" alt="Garden bed"> </picture> </body></html>