Web StyleElement API | StyleElement media property
In Web API there are style elements which have media attribute. To fetch this media attribute we use HTMLStyleElement.media property, which specifies the intended destination medium for style information.
Syntax:
label = style.media style.media = label
label is a string which describes a single medium or a comma-separated list.
Example: get the media attribute
<!DOCTYPE html> <html> <head> <title> StyleElement media property </title> <style> a:focus { background-color: magenta; } </style> <link id="Link" rel="stylesheet" type="text/css" media="screen" /> <script type="text/javascript"> function getmedia() { var label = document.getElementById('Link'); document.getElementById( 'media').innerHTML = label.media; } </script> </head> <body> <center> <h1 style="color:green;"> GeeksForGeeks </h1> <h2>HTML StyleElement media property</h2> <button onclick="getmedia();" id="btn">Get media</button> <p id='media'></p> </center> </body> </html> |
Output:
Click the button:

When the button is clicked:

Supported Browsers:
- Google Chrome
- Edge 12
- Internet Explorer
- Firefox
- Safari
- Opera
Recommended Posts:
- Web HTMLStyleElement API | StyleElement type property
- CSS | media queries
- CSS | @media Rule
- Bootstrap | Media queries
- Bootstrap 4 | Media Objects
- Media Objects in Bootstrap with Examples
- How to target desktop, tablet and mobile using Media Query ?
- YouTube Media/Audio Download using Python | pafy
- What is the difference between “screen” and “only screen” in media queries?
- CSS | transition-property Property
- CSS | right Property
- CSS | top Property
- CSS | all Property
- CSS | nav-down property
- CSS | nav-right property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



