Favicon API

Find the favicon of any web site. One URL, ready for <img src>.

  • Returns a redirect to the favicon of a web site given by its domain name.
  • Finds the icon the way a browser does:
    • icons declared in the head of the main page (icon, shortcut icon, apple-touch-icon),
    • then the standard locations: /favicon.svg, /favicon.png, /apple-touch-icon.png, /favicon.ico.
  • Picks the best icon: the largest one (by the sizes attribute, SVG is the largest), formats other than ICO first.
  • Checks that the icon really exists and is an image.
  • Results are cached, so repeated requests are fast.

If you have found this API useful but feel that a feature is missing, please share your suggestions with us via email.


Get the favicon of a web site

curl -I 'https://favicon.intami.pl/favicon/wp.pl'
URL parameterDescriptionHints
domainDomain name of the web site, e.g. wp.pl or www.github.com.Required. Without scheme, path and port; IP addresses are not accepted. International domain names are supported.
fallbackQuery parameter: URL of an image to redirect to when the favicon cannot be determined.Optional. Absolute http(s) URL, URL encoded.

Responses:

StatusDescription
301 Moved PermanentlyThe Location header contains the URL of the favicon.
302 FoundThe favicon cannot be determined and fallback is given: the Location header contains the fallback URL.
404 Not FoundThe favicon cannot be determined (no icon or the site cannot be reached).
400 Bad RequestInvalid domain name or fallback URL.

Example - download the favicon:

curl -L 'https://favicon.intami.pl/favicon/github.com' --output favicon

Example - show the favicon in a page:

<img src="https://favicon.intami.pl/favicon/github.com" width="32" height="32" alt="">

Example - show your own image when there is no favicon:

<img src="https://favicon.intami.pl/favicon/github.com?fallback=https%3A%2F%2Fexample.com%2Fdefault-icon.png" width="32" height="32" alt="">

JavaScript library

A small script (favicon.js, no dependencies) that shows favicons in your page without building the URLs yourself. Mark images with the data-site-url attribute and the script does the rest: it asks the API for the favicon of the site and, when there is one, puts it into src of the image. When there is no favicon, the image keeps its own src, so it works as a placeholder.

1. Add the script once, e.g. at the end of <head>:

<script src="https://favicon.intami.pl/favicon.js" defer></script>

2. Mark the images:

<img data-site-url="wp.pl" src="default-icon.png" width="32" height="32" alt="">
<img data-site-url="https://github.com/golang/go" src="default-icon.png" width="32" height="32" alt="">

Attributes and classes:

NameDescriptionHints
data-site-urlThe web site whose favicon is shown: a domain name (wp.pl) or any URL of the site (https://www.wp.pl/news?id=1).Required. Only the host name is used; img elements only.
srcImage shown while the favicon is loading and when there is none.Optional. Use your default icon or a transparent image.
class favicon-foundAdded when the favicon was found and set as src.
class favicon-missingAdded when the site has no favicon or data-site-url is invalid; src is not changed.E.g. img.favicon-missing { display: none; } hides such images.

How it works:

  • The favicon is loaded in the background; src is replaced only when it has loaded, so there are no broken image icons.
  • Images added to the page later (e.g. by AJAX or a JavaScript framework) and changes of data-site-url are handled automatically.
  • Every site is asked only once per page, even when it is shown many times; the browser caches the answers for a day.
  • The script talks to the server it was loaded from.

Example - hide sites without a favicon:

<style> img.favicon-missing { display: none; } </style>
<a href="https://github.com"><img data-site-url="https://github.com" width="16" height="16" alt=""> GitHub</a>

Live demo:

github.com
https://www.wp.pl/news
bbc.co.uk
no-such-site-xyz123.com
(no favicon, placeholder stays)

Try it


API Limits

This API has no request limit.
Found icons are cached for 7 days, missing icons for 1 day; responses can be cached by browsers for 1 day.


Explore the API