Open In App

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

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 on which devices the linked document would appear and be compatible.

Various devices values:



Example: In this example, we will see the use of media attribute




<!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:

Article Tags :