How to define a favicon? Is it mandatory to define it?

Asked

Viewed 398 times

3

There are certain things that, by not doing constantly, I always end up forgetting how to do it. And one of them is the definition of a favicon for my website.

What is the tag and attributes that I should use for the correct definition of a favicon on my site? (I always forget, but now I won’t forget more :p)

Another question I’d like to ask is:

  • Why, even if not defining a favicon, always get a 404 error?

Example (with built-in PHP server, but also with other languages and libraries):

Favicon retornando erro 404

After all:

  • the use favicon is optional or not?

  • He always needs to have that way /favicon.ico?

  • In the case of how to define it, maybe I was wrong even on account of the optional part, sorry, removed.

1 answer

4


The favicon is defined by a relation element (<link rel>) in the header of your page, within the element <header>.

While the presence of a favicon is optional, your browser will always try to download a file from the default setting - {root}/favicon.ico.

The MIME guys image/png, image/gif or image/ico are supported by all modern browsers. On some browsers, animated Gifs will only have the first frame used (IE and Safari, at the time of this response.)

Support for other formats is available, but implementation is not consistent.

The path to your image can be set in the property href.

<link rel="icon" type="image/png" href="http://example.com/myicon.png">
<link rel="shortcut icon" href="/img/favicon.ico" />

Source.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.