The media attribute tells the browser when a resource should apply. Put it on <link rel="stylesheet">, <style>, or <source> (often inside <picture>). The value is a CSS media type or media query list — for example screen, print, or (min-width: 768px).
If the condition matches the current device or context, the stylesheet or source is used; otherwise it is skipped for styling (or the browser moves to the next <source>). Default for link and style is all when omitted.
Baseline · Widely available.
Not deprecated and not experimental. Stable across modern browsers since about July 2015.
Not the same as CSS @media.
media on HTML gates an entire stylesheet or source. @media inside a CSS file switches individual rule blocks. See CSS @media.
Syntax
HTML Syntax
syntax.html
<link rel="stylesheet" href="…" media="query">
<style media="query">…</style>
<source srcset="…" media="query">
query is a media type, a media feature query, or a comma-separated list of either.
Values
Attribute Values
Common media types and query patterns you can use:
Value
Description
Try it
all
Default. Applies in every context (screen, print, and more)
Widen the viewport past 700px to load the wide source.
How It Works
List sources first. The browser checks each <source> in order.
media decides eligibility. If (min-width: 700px) matches, that srcset is used.
Fallback <img>. Always include an img with alt for accessibility.
Art direction. This is for different crops or layouts, not only file size (see also srcset).
Edge Cases & Pitfalls
Most surprises come from mixing up HTML media with CSS @media, or expecting downloads to stop.
compare
HTML media vs CSS @media
The attribute gates a whole stylesheet or source. @media switches rules inside one CSS file. Both are valid; pick one clear strategy.
performance
Non-matching CSS may still download
Browsers often fetch print or breakpoint sheets anyway, but they usually do not block rendering like the main screen stylesheet.
a11y
Do not rely on speech
Screen readers do not consume author CSS the way visual browsers do. Use semantic markup and ARIA, not media="speech".
picture
Always keep an <img> fallback
Inside <picture>, <source media> alone is not enough. The img provides the default image and accessible name.
legacy
Skip obsolete media types
handheld, tv, tty, and similar types are deprecated. Prefer feature queries like (max-width: …).
Compatibility
Browser Support
media is an HTML attribute for link, style, and source in the browser. It is not a Node.js, Deno, or Bun API.
✓ Baseline · Widely available
media
Widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera support media on stylesheets and picture sources.
97%Global support (approx.)
Google Chrome4+
Full support
Mozilla Firefox4+
Full support
Apple Safari4+
Full support
Microsoft Edge12+
Full support
Opera15+
Full support
Samsung Internet4+
Full support
Internet Explorer9+
Supported
mediaWidely supported
Bottom line: Safe to use for print sheets, breakpoints, and picture art direction. Prefer modern feature queries over obsolete media types.
Remember
Key Takeaways
Role: apply a stylesheet or source only when a media condition matches.
Elements:<link>, <style>, and <source>.
Common values:screen, print, and width queries.
vs @media: HTML gates a whole sheet; CSS @media gates rules inside a file.
One line:media answers “when should this stylesheet or source apply?”
Frequently Asked Questions
It sets when a stylesheet or picture source should apply. The value is a CSS media type (like screen or print) or a media query (like (min-width: 768px)). If the condition matches, the resource is used.
link (especially for stylesheets), style, and source (inside picture, and also usable with video/audio sources). Default for link and style is all when the attribute is omitted.
They share the same query syntax, but media on link or style decides whether an entire stylesheet applies. @media inside a CSS file switches individual rule blocks within one file.
Use media="print" on a link or style element. Those styles apply when printing or in print preview, and they do not change the normal screen layout.
Often yes. Browsers may still fetch it, but a non-matching media query typically does not block rendering the way the main screen stylesheet does.
No. speech is a valid media type, but screen readers do not apply author CSS like visual browsers. Rely on semantic HTML and ARIA instead.