Back to Content

HTMLSourceElement: media property

files/en-us/web/api/htmlsourceelement/media/index.md

latest1.2 KB
Original Source

{{APIRef("HTML DOM")}}

The media property of the {{domxref("HTMLSourceElement")}} interface is a string representing the intended destination medium for the resource. The value is a media query, which is a comma separated list of media-types, media-features, and logical operators.

It reflects the media attribute of the {{HTMLElement("source")}} element.

Value

A string.

Examples

html
<video>
  <source
    id="el"
    src="largeVideo.mov"
    type="video/quicktime"
    media="screen and (width >= 600px)" />
</video>
js
const el = document.getElementById("el");
console.log(el.media); // Output: "screen and (width >= 600px)"
el.media = "(width >= 800px)"; // Updates the media value

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also

  • {{domxref("HTMLSourceElement.type")}}
  • {{domxref("HTMLSourceElement.sizes")}}
  • {{domxref("HTMLSourceElement.src")}}
  • {{domxref("HTMLSourceElement.srcset")}}
  • {{htmlelement("source")}}
  • {{htmlelement("picture")}}
  • {{htmlelement("audio")}}
  • {{htmlelement("video")}}
  • Using media queries