Skip to content

this is the right way to do light and dark favicon #13097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

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
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
2 participants