Open In App

HTML DOM Source media Property

The HTML DOM Source media Property is used to set or return the value of the media attribute of the <source> element. The <source> media attribute is used to accept any valid media query that would normally be defined in a CSS. This attribute can accept several values.

 



Syntax:

Possible Operators

DEVICES

VALUES

Return Value: It returns a String value, which represents the indented type of the media resource

Example: Below HTML code returns the source media property.




<!DOCTYPE html>
<html>
  
<head>
    <style>
        body {
            text-align: center;
        }
  
        h1 {
            color: green;
        }
    </style>
</head>
  
<body>
    <h1>GeeksforGeeks</h1>
    <h2>HTML DOM Source media property</h2>
  
    <audio controls>
        <source id="mySource" src="gameover.wav" 
                type="audio/mpeg" media="(min-width: 600px)">
  
        <source src="gameover.ogg" type="audio/ogg">
    </audio>
    <p>Click the button to get the media of the source file.</p>
  
    <button onclick="myGeeks()">
        Get Media
    </button>
  
    <p id="demo"></p>
  
    <script>
        function myGeeks() {
            var x = document.getElementById("mySource").media;
            document.getElementById("demo").innerHTML = x;
        }
    </script>
</body>
  
</html>

Output :

Supported Browsers:


Article Tags :