Skip to content

Instantly share code, notes, and snippets.

@AndreasHnida
Created August 9, 2025 23:43
Show Gist options
  • Save AndreasHnida/1d59762bcfc00dac96ea48d11ee75511 to your computer and use it in GitHub Desktop.
Save AndreasHnida/1d59762bcfc00dac96ea48d11ee75511 to your computer and use it in GitHub Desktop.
Favicon for Light and Dark Mode in Nuxt #favicon #html #nuxt #vue
export default defineNuxtConfig({
modules: [
'@nuxtjs/tailwindcss',
'@nuxt/content',
'@nuxtjs/google-fonts'
],
googleFonts: {
families: {
Inter: [300, 400, 500, 600, 700],
Poppins: [300, 400, 500, 600, 700, 800]
},
display: 'swap'
},
app: {
head: {
link: [
// Default favicon for browsers that don't support media queries
{ rel: 'icon', type: 'image/png', href: '/images/favicon-light-mode.png' },
// Light mode favicon
{
rel: 'icon',
type: 'image/png',
href: '/images/favicon-light-mode.png',
media: '(prefers-color-scheme: light)'
},
// Dark mode favicon
{
rel: 'icon',
type: 'image/png',
href: '/images/favicon-dark-mode.png',
media: '(prefers-color-scheme: dark)'
}
],
script: [
// Script to dynamically update favicon based on color scheme
{
innerHTML: `
(function() {
const updateFavicon = () => {
const isDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
const favicon = document.querySelector('link[rel="icon"]:not([media])');
if (favicon) {
favicon.href = isDark ? '/images/favicon-dark-mode.png' : '/images/favicon-light-mode.png';
}
};
// Initial update
updateFavicon();
// Listen for color scheme changes
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', updateFavicon);
})();
`,
type: 'text/javascript'
}
]
}
},
devtools: { enabled: true }
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment