Curriculum
Course: HTML Basic
Login

Curriculum

HTML Basic

HTML Introduction

0/1

HTML Editors

0/1

HTML Elements

0/1

HTML Attributes

0/1

HTML Headings

0/1

HTML Paragraphs

0/1

HTML Styles

0/1

HTML Formatting

0/1

HTML Quotation

0/1

HTML Comments

0/1

HTML Colors

0/1

HTML Favicon

0/1

HTML Page Title

0/1

HTML Block and Inline

0/1

HTML Iframes

0/1

HTML Java Script

0/1

HTML File Paths

0/1

HTML - The Head Element

0/1

HTML Style Guide

0/1

HTML Entities

0/1

HTML Symbols

0/1
Text lesson

The Picture Element

HTML <picture> Element

The <picture> element in HTML enhances the ability of web developers to define various image sources for different scenarios.

Within the <picture> element, there are multiple <source> elements, each pointing to distinct images via the srcset attribute. This enables the browser to select the most appropriate image based on the current viewing conditions or device specifications.

The media attribute associated with each <source> element specifies the conditions under which a particular image is deemed most fitting, allowing for more responsive and adaptive image display across various devices and screen sizes.

Example

<picture>
  <source media=”(min-width: 650px)” srcset=”image1.jpg”>
  <source media=”(min-width: 465px)” srcset=”image2.jpg”>
  <img src=”img_flower.jpg”>
</picture>
Note: Always place an <img> element as the last child within the <picture> element. Browsers that lack support for the <picture> element, or instances where none of the <source> tags match, will resort to using the <img> element.

Usage of Picture Element

The <picture> element serves two primary purposes:

1. Bandwidth

If your screen or device is compact, loading a large image file isn’t essential. The browser will prioritize the first <source> element that aligns with attribute values and disregard subsequent elements.

2. Format Support

Certain browsers or devices might lack support for specific image formats. Employing the <picture> element allows you to include images in various formats, with the browser utilizing the first recognized format while disregarding subsequent elements.

Example

<picture>
  <source srcset=”image1.png”>
  <source srcset=”img_flower.jpg”>
  <img src=”img_farms.gif” alt=”Farms” style=”width:auto;”>
</picture>

Note: The browser will select the initial <source> element that matches the attribute values and disregard any subsequent <source> elements.