1

I'd like to have a favicon appear in a visitor's browser tab and bookmarks when they visit my site. How can I accomplish that?

1

Method 1 (HTML 4.01)

You can use this code:

<!DOCTYPE html 
      PUBLIC "-//W3C//DTD HTML 4.01//EN"
      "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en-US">
<head profile="http://www.w3.org/2005/10/profile">
<link rel="icon" 
      type="image/png" 
      href="http://example.com/myicon.png">
[…]
</head>
[…]
</html>

replace http://example.com/myicon.png with the actual URL of your favicon image.

Method 2 (XHTML 1.0)

<!DOCTYPE html 
  PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html
  xmlns="http://www.w3.org/1999/xhtml" 
  xml:lang="en-US"
  lang="en-US">
<head profile="http://www.w3.org/2005/10/profile">
<link rel="icon" 
  type="image/png" 
  href="http://example.com/myicon.png" />
[…]
</head>
[…]
</html>

As you can see the XHTML 1.0 version is very similar. And again, replace http://example.com/myicon.png with the actual URL of your favicon image.

Method 3 (Predefined)

A second method for specifying a favicon relies on using a predefined URI to identify the image: "/favicon", which is relative to the server root. This method works because some browsers have been programmed to look for favicons using that URI. This approach is inconsistent with some principles of Web architecture and is being discussed by W3C's Technical Architecture Group (TAG) as their issue siteData-36. To summarize the issue: The Web architecture authorizes site managers to manage their URI space (for a given domain name) as they see fit. Conventions that do not represent community agreement and that reduce the options available to a site manager do not scale and may lead to conflict (since there is no well-known list of these predefined URIs). One practical consideration illustrates the problem: many users have Web sites even though they do not have their own domain name. These users cannot specify favicons using the second method if they cannot write to the server root. However, they can use method one to specify a favicon since it is more flexible and does not constrain the site manager to use a single favicon at a single place on the site.

There are a few other well-known encroachments on URI space, including the "robots.txt" file and the location of a P3P privacy policy. The Technical Architecture Group is exploring alternatives that do not impinge on URI space without license.

Source: http://www.w3.org/2005/10/howto-favicon

  • 1
    One of the reasons I had so much success in my life is because of the research I was able to do and the ability to find an answer, solution, or an idea of what else to look for. Another part of this was my ability to see complex technologies as a series of simple technologies in step order. I made a career of solving problems that I had no earthly idea about, but was able to figure out and solve rather quickly. I suspect it takes a particular kind of brain to do this, but I also think it is a mind-set. Clearly, you have all of these! If I knew your parents, I would be speaking praise over you. – closetnoc Oct 5 '14 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.