Horje

How to Use <source> within <picture> to define different images based on the viewport width

See the Eample.

index.html
Example: HTML
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>

<h1>The picture element</h1>

<p>Resize the browser window to load different images.</p>

<picture>
  <source media="(min-width:650px)" srcset="https://horje.com/avatar.png">
  <source media="(min-width:465px)" srcset="https://horje.com/avatar.png">
  <img src="https://horje.com/avatar.png" alt="Horje" style="width:auto;">
</picture>

</body>
</html>

Output should be:

How to Use <source> within <picture> to define different images based on the viewport width




Type:
html
Category:
Web Tutorial
Sub Category:
HTML Tag
Uploaded by:
Admin