Ask coding questions

← Back to all posts
favicon doesn't appear
wildbarbarian (0)

i'm making a website on replit and when i try to add a favicon, it doesn't load. it gives a 404 error in the console. screenshots are attached.

Answered by Coder100 (18207) [earned 5 cycles]
View Answer
Coder100 (18207)

You forgot to serve favicon.png

silly mistake, here's a working repl:

don't forget to hard refresh ctrl + shift + r

remember: in express and node, no file is public to the server unless you tell it to

malvoliothegood (871)

In the head of your web pages try the following tag:
<link rel="icon" type="image/png" href="/favicon.png">
In any case the icon should be sent back from the server if the tag above is not present, as long as the icon file is at the same level as your index.html file.

Note that you do not need a link tag that references the favicon in the index.html page as browsers look for them automatically in the root of the site.

wildbarbarian (0)

@malvoliothegood hmm, i added the code and it still doesn't work :(

malvoliothegood (871)

@soshort Yes, I found this out after making the comment. I had another go and came up with this:
I think it may be a similar idea to Coder100's.