HTML media attribute Last Updated : 06 May, 2025 Comments Improve Suggest changes Like Article Like Report The HTML media attribute is employed to specify the media or device the coupled document is optimized for. This attribute specifies that the target URL is designed for special devices like iPhones, speech, or print media. syntax<element media="value">Supported TagsElementDescription<a>Represents a hyperlink, linking to another resource.<area>Defines a clickable area inside an image map.<link>Specifies the relationship between a document and an external resource.<source>Specifies multiple media resources for media elements like <audio> and <video>.<style>Contains CSS rules to style HTML elements.HTML media attribute ExamplesExample1: In this example we demonstrates the use of the media attribute, which is incorrect for anchor elements. Instead, it uses the target attribute to specify whether links open in the same or a different tab. index.html <!DOCTYPE html> <html> <head> <title>HTML media Attribute</title> </head> <body> <h2>HTML media Attribute</h2> <a href="https://ide.geeksforgeeks.org/community" target="_self"> Click to open in the same tab </a> <br /> <a href="https://www.geeksforgeeks.org/community" target="_blank"> Click to open in a different tab </a> </body> </html> Note: The HTML iframe syntax is correct, the https://geeksforgeeks.org website does not allow itself to be embedded in iframes on other domains. This is due to protective headers (X-Frame-Options, CSP) that prevent clickjacking and preserve content security. As a result, the iframe appears broken, even though the code itself is valid. You can use some other website link to check the output.Example2: In this example the media attribute specifies conditions (such as screen width) under which different image sources defined in the <source> element are applied for responsive design. html <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> </head> <body> <picture> <source media="(min-width: 900px)" srcset= "https://media.geeksforgeeks.org/wp-content/uploads/20190328185307/gfg28.png" /> <source media="(min-width: 600px)" srcset= "https://media.geeksforgeeks.org/wp-content/uploads/20190809013546/gfg_350X350.png" /> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20190521140445/gfglogo2.png" style="width: auto" /> </picture> </body> </html> Output: Change the browser size. Supported Browsers: The browsers supported by HTML media attribute are listed below: Google ChromeEdge Internet Explorer Firefox OperaSafari Comment More infoAdvertise with us Next Article HTML media attribute V Vijay Sirra Follow Improve Article Tags : Web Technologies HTML HTML-Attributes Similar Reads HTML accept Attribute HTML accept Attribute specifies the type of file that the server accepts. This attribute can be used with <input> element only. This attribute is not used for validation tools because file uploads should be validated on the Server.Syntax:<input accept = "file_extension"> Note: This attri 3 min read HTML accept-charset Attribute The accept-charset attribute is used to define the character encoding and is used for form submission. The default value of the accept-charset attribute is "UNKNOWN" string which indicates the encoding equals to the encoding of the document containing the <form> element. Syntax:<form accept 2 min read HTML accesskey Attribute The HTML accesskey attribute defines a keyboard shortcut to activate or focus an element.It assigns a keyboard key combination to trigger an element (like a link or button).Browser support and specific key combinations vary (e.g., Alt + key on Windows, Ctrl + key on macOS).Use it sparingly and provi 3 min read HTML action Attribute The HTML action attribute is used to specify where the form data should be sent on submission. It allows the browser to send the data to the specified location, enabling server-side scripts to process the data and generate a response.Note: It can be used in the <form> element. Syntax:<form 3 min read HTML align Attribute In HTML, the align attribute is used to control the alignment of elements on a webpage. Whether it's for text, images, or tables, the align attribute helps to position content in relation to its surrounding elements.Syntax<element_name align="left | right | center | justify">Attribute ValuesAt 4 min read HTML alt attribute The alt attribute in HTML provides alternative text for images, aiding accessibility and providing context for screen readers.Syntax:<img src=" " alt=" " >HTML<html> <body> <h1>GeeksforGeeks Logo</h1> <img src="https://media.geeksforgeeks.org/wp-content/uploads/20190 3 min read HTML async Attribute The HTML <script> async attribute is used to load and execute external scripts without blocking the rest of the page from loading. This speeds up page load times. It only works with external scripts (when the src attribute is present).Syntax:<script src="path-to-script.js" async></scr 3 min read HTML autocomplete Attribute The HTML autocomplete Attribute is used to specify whether the input field autocompleted would be on or off. When the autocomplete attribute is set to on the browser will automatically complete the values based on what the user entered before. It works with input fields such as text, search, URL, em 3 min read HTML autoplay Attribute The HTML autoplay Attribute, a boolean attribute, enables audio or video elements to start playing automatically when the page loads, providing seamless playback without interruption.Syntax: <element autoplay> Supported ElementsIt can be used with <audio> and <video> elements. Elem 2 min read HTML autofocus Attribute The HTML autofocus attribute is a powerful tool that enhances user experience by automatically setting the focus to a specific element when a webpage loads. Syntax<input type="text" autofocus> Note: This attribute is boolean, meaning it can either be present or absent.Supported TagsElementPurp 2 min read Like