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

2

There are certain things that, by not doing constantly, I always forget how to do it. And one of them is setting favicon to my site.

What tags and attributes should I use to correctly define a favicon on my site? (I always forget, but now I will not forget anymore: p)

Another question I'd like to draw is:

  • Why, even if I do not set favicon , do I always get a 404 error?

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

After all:

  • Is favicon optional or not?

  • Does it always need to have that path /favicon.ico ?

asked by anonymous 27.01.2017 / 17:00

1 answer

3

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

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

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

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

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

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

Font .

    
27.01.2017 / 17:05