Skip to content
Related Articles

Related Articles

How to specify media type of the target URL in HTML5 ?

View Discussion
Improve Article
Save Article
  • Last Updated : 28 Jun, 2021
View Discussion
Improve Article
Save Article

You can easily specify the media type of the target URL in HTML5 using the media attribute of HTML. This attribute is used to specify that the target URL is designed for special devices (like iPhone, Android, etc), speech or print media, projectors, tv, and so on.

Syntax:

<a href="" media="screen" target=”_blank”> Click here</a>

Note: The media attribute can only be used if the href attribute is used as it specifies the linked document. The media attribute is used to specify how and in which devices the linked document would appear and be compatible.

Various devices values:

  • all : It is most suited for all media-type devices.
  • screen : It is used for computer screens, smartphones, etc.
  • tv : It is used for television-type devices (low resolution, or the one with limited scroll ability).
  • print : It is used for the print preview mode/printed page’s mode.

Example: 

HTML




<!DOCTYPE html>
<html>
  
<head>
    <style>
        h1 {
            color: green;
        }
    </style>
</head>
  
<body>
    <center>
        <h1>Welcome To GFG</h1>
        <a href="https://ide.geeksforgeeks.org/" 
            media="print" target="_blank">
            Click here for print media
        </a>
        <br /><br />
        <a href="https://ide.geeksforgeeks.org/" 
            media="tv" target="_blank">
            Click here for screen media
        </a>
    </center>
</body>
  
</html>

Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!