Skip to content

Conversation

gordonwoodhull
Copy link
Contributor

@gordonwoodhull gordonwoodhull commented Jul 17, 2025

It uses the media attribute of the <link /> tag.

E.g.

<link href="./moon-face.png" rel="icon" type="image/png" media="(prefers-color-scheme:dark)">
<link href="./sun-face.png" rel="icon" type="image/png" media="(prefers-color-scheme:light)">

If this were more than a draft, it would fix #13005.

Unfortunately it only works on Chrome 😦 but it's a very nice, clean way to do this.

Firefox and Safari ignore media on link[rel="icon"] and take the first or second icon only, respectively.

Another approach is to dynamically set the href on the icon, but this only works consistently for Firefox and Chrome; Safari seems to have very aggressive caching which makes this difficult/impossible in a standard way.

@posit-snyk-bot
Copy link
Collaborator

posit-snyk-bot commented Jul 17, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

using the media attribute of link tag
unfortunately it only works on Chrome :-(
but it's a very nice way

TODO: also allow project.favicon to choose icon resource
or have {light,dark}
@gordonwoodhull gordonwoodhull force-pushed the feature/favicon-link-media-color-scheme branch from b8144c3 to 80f9f30 Compare July 17, 2025 20:47
@cscheid cscheid added this to the v1.9 milestone Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

light and dark favicon
3 participants