question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ability to specify link media attribute

See original GitHub issue

Describe 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:open
  • Created 2 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Rich-Harriscommented, Apr 24, 2022

Screen readers rely on the browser’s accessibility tree, which takes things like display: none and pseudo elements into account. My understanding is that media="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…

.foo { color: red; }

@media (screen) {
  .bar { color: green; }
}

@media (print) {
  .baz { color: blue; }
}

…resulted in this…

<link rel="stylesheet" href="/_app/assets/abc123.css">
<link rel="stylesheet" href="/_app/assets/def456.css" media="screen">
<link rel="stylesheet" href="/_app/assets/ghi789.css" media="print">

…but I expect that would require cooperation from Vite.

0reactions
espositofulviocommented, Apr 24, 2022

I can see your idea of splitting based on the media query is actually better, surely I second that!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found