Open In App

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

Improve
Improve
Like Article
Like
Save
Share
Report

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:

  • 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: In this example, we will see the use of media attribute

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:


Last Updated : 06 Jun, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads