Ability to specify link media attribute
See original GitHub issueDescribe the problem
For accessibility and performance it would be good to have a way to specify the media attribute for the generated CSS. I mean that all the
<link rel="stylesheet" href="_app/index.012930190.css">
could be actually something like
<link rel="stylesheet" href="_app/index.012930190.css" media="screen">
thus many screen or braille readers, etc., could avoid downloading the stylesheets.
Describe the proposed solution
I’m not sure what a good a good solution would be but I guess I would prefer having a default media=“screen” if nothing specified and maybe the ability in sfc files to do something like:
<style media="screen"> <!-- or print etc. -->
</style>
Alternatives considered
No response
Importance
nice to have
Additional Information
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
HTML link media Attribute - W3Schools
This attribute is mostly used with CSS style sheets to specify different styles for different media types. The media attribute can accept several...
Read more >HTML | <link> media Attribute - GeeksforGeeks
This attribute used to specify a different style for different media type. The media attribute can accept several values. Syntax: <link media=" ...
Read more >HTML link media Attribute - Dofactory
This attribute specifies that a stylesheet or icon is designed for certain mobile devices, print media, and others. media accepts multiple media or...
Read more >The External Resource Link element - HTML - MDN Web Docs
This attribute specifies the media that the linked resource applies to. Its value must be a media type / media query. This attribute...
Read more >What is the utility of the media attribute in the Link tag?
An advantage of using the media attribute in a link tag that was not mentioned is that by including styles this way we...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Screen readers rely on the browser’s accessibility tree, which takes things like
display: none
and pseudo elements into account. My understanding is thatmedia="screen"
stylesheets are still generally used (they are screen readers, after all), so this would have no effect; if stylesheets were excluded then the accessibility tree would likely be incorrect.In short, the
media
attribute should only be used if it was specified by the CSS author. What would be cool is if stylesheets were split up based on media query, i.e. this……resulted in this…
…but I expect that would require cooperation from Vite.
I can see your idea of splitting based on the media query is actually better, surely I second that!