TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

HTML picture Tag

HTML picture Tag with html tutorial, tags, anchor, img, div, entity, textarea, marquee, p tag, heading tag, h1, h2, table, formatting, attribute, elements, ol, ul, Input Types, block element tag, inline element tag, html tags, phrase tag, head, body, form, lists, symbols etc.

<< Back to HTML

HTML <picture> tag

HTML <picture> tag is used in responsive web designing where we need to load the different images based on their viewport, height, width, orientation, and pixel density.

The <picture> tag contains one or more <source> elements and one <img> elements.

According to the viewport, the matching image will be loaded from different <source> tag, and if no source contains the matching image, then the default image present in <img> tag will be displayed on the browser.

This tag is a new tag in HTML5.

Syntax

<picture>
	<source srcset="" media="">
	<img src="">
</picture>

Following are some specifications about the HTML <picture> tag

Display Inline
Start tag/End tag Both Start and End tag
Usage Image

Example

<!DOCTYPE html>
<html>
<head>
	<title>Picture Tag</title>
	<style>
	body{
	    text-align: center;
                   }
	   p{
	     font-size: bold;
	     font-size: 20px;	
	   color: green;  
                    }
	</style>
</head>
<body>
<h2>Example of picture tag</h2>
<p>Resize the page to see the different versions of the images at different viewports, and as per viewport image will be automatically changed.</p>
<picture>
    <source srcset="download1.jpg" media="(min-width: 750px)">
    <source srcset="pic2.jpg" media="(min-width: 450px)">
    <img srcset="rose.jpg" alt="default image" style="width: auto;">
</picture>
</body>
</html>
Test it Now

Output:

HTML picture tag

Attribute:

Tag-specific attributes:

Attribute Value Description
media media_query It defines and accept any media query which can be defined in CSS.
srcsetHTML Tags List URL It defines the URL of the image which can be used for different situations. (Required)
type video/ogg
video/mp4
video/webM
audio/ogg
audio/mpeg
It determines the MIME type
src URL It specifies the location of the image.

Global attribute:

HTML <picture> tag supports the global attributes in HTML.

Supporting Browsers

Elementchrome browser Chromeie browser IEfirefox browser Firefoxopera browser Operasafari browser Safari
<picture>YesNoYesYesYes
Next TopicHTML pre Tag




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf