DEV Community

Cover image for media attribute in link tag
Robin Kartikeya Khatri
Robin Kartikeya Khatri

Posted on

media attribute in link tag

Why is media attribute written inside the link tag in html markup? Is it necessary to use media attribute in link tag to create a responsive website? Isn't CSS written using @media (max-width: 1100px) in a CSS file without writing the media attribute? Is it necessary to use @media (max-width: 1100px) in CSS file even after writing media attribute in link tag?

Discussion (2)

Collapse
patarapolw profile image
Pacharapol Withayasakpunt

I feel like it is equivalent to @media applied to the whole import statement in SCSS.

It's yet another way to do things without building the CSS first, like it comes from third party CDN.

I saw it used for

media="(prefers-color-scheme: dark)" 
media="(prefers-color-scheme: no-preference), (prefers-color-scheme: light)" 
Enter fullscreen mode Exit fullscreen mode
Collapse
robinkartikeyakhatri profile image
Robin Kartikeya Khatri Author

Great