DEV Community

Lucy Linder
Lucy Linder

Posted on • Updated on • Originally published at blog.derlin.ch

Get favicons from any domain using a hidden google API

Did you know ?

Google offers a secret URL that can automatically pull the favicon image of any domain. Cherries on the cake, we can ask for different sizes and the images returned are in PNG format (not ICO), meaning they will render correctly in all browsers using the <img> tag.

The API works using a simple GET:



https://www.google.com/s2/favicons?domain=${domain}&sz=${size}


Enter fullscreen mode Exit fullscreen mode

The query parameters are:

  • domain: mandatory, the domain you are interested in,
  • sz: optional, a size hint such as 256.

In case the right size is not found, it will return the default one, usually 16x16.


https://www.google.com/s2/favicons?domain=dev.to&sz=128
128x128

https://www.google.com/s2/favicons?domain=dev.to&sz=512 (nothing found for 512x512, so returns a 16x16 PNG)
16x16 fallback

https://www.google.com/s2/favicons?domain=stackoverflow.com&sz=128 (yep, sometimes the quality is far from optimal)
stackoverflow 128x128

Oldest comments (15)

Collapse
 
mtimofiiv profile image
fiiv

Nice writeup! Privacy-friendly search engine DuckDuckGo also has one similar to the Google one:



https://icons.duckduckgo.com/ip3/dev.to.ico


Enter fullscreen mode Exit fullscreen mode

Also there's one I made called Icon Horse that has some additional features:



https://icon.horse/icon/dev.to


Enter fullscreen mode Exit fullscreen mode
Collapse
 
derlin profile image
Lucy Linder

Wasn't aware of those ones, nice to know thanks !
I would just state that Icon Horse is not free (but still a very nice tool).

Do you know if duckduckgo supports parameters, such as the size hint for example ?

Collapse
 
mtimofiiv profile image
fiiv

To my knowledge DDG doesn’t have various customisation params available.

Icon Horse is free, but premium features cost money.

Collapse
 
tr11 profile image
Tiago Rangel

Icon horse seems quite nice! Big image, doesn't stop at redirections, very cool.

Collapse
 
abhidadhaniya23 profile image
Abhi Dadhaniya

icon.horse is the best one... Thanks for the sharing

Collapse
 
ross_bg profile image
Rosen Simov

Your Icon Horse service looks amazing! I'll give it a try real soon.

Collapse
 
derlin profile image
Lucy Linder

Here is yet another service: favicongrabber.com

The call looks like:

http://favicongrabber.com/api/grab/dev.to
Enter fullscreen mode Exit fullscreen mode

The response is a JSON with all the available icons (use ?pretty=true for nice json formatting):

{
  "domain": "dev.to",
  "icons": [
    {
      "sizes": "192x192",
      "src": "https://res.cloudinary.com/practicaldev/image/fetch/s--t7tVouP9--/c_limit,f_png,fl_progressive,q_80,w_192/https:/practicaldev-herokuapp-com.freetls.fastly.net/assets/devlogo-pwa-512.png"
    },
    ...
}
Enter fullscreen mode Exit fullscreen mode

However, I got some gateway timeouts and trying favicongrabber.com/api/grab/stacko... currently returns:

{"error":"General API error."}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
pomdtr profile image
Achille Lacoin • Edited

Thanks for mentioning this ! I created a little cli to expose this api: github.com/pomdtr/fetch-favicon

Collapse
 
wexxat profile image
xailor

How do you guys mitigate the CORS issue? I tried to use this with fetch API but it's giving me the CORS error for both google and Duckduck go

Collapse
 
prajwal89 profile image
Prajwal Hallale

I have made a tool for downloading favicons
Website favicon downloader

Collapse
 
swanbro_d31fad871 profile image
Edward Swangren

Cool! I found a few more

curl
wget
my browser's url bar

what's special about those is they didn't build useless crap to farm me for ad revenue. so no thanks, but also no thanks.

Collapse
 
firozishakk profile image
Firoz ishakk

how can i change the default favicon (if a website doesn't have a favicon, it shows a blurry image of a sphere.) I want to include an image i have created .. let's say "/logo@512.png" ,i need this as default if no other images are present. How do i do it ?

Collapse
 
glitchedgitz profile image
Gitesh Sharma

Did you find any solution do this?

Collapse
 
ajay_kumar profile image
Ajay Kumar

Awesome, Thanks ;)

Collapse
 
private_proxy profile image
Private Proxies

That's a great tip! The Google API is indeed useful for quick favicon retrieval. However, it has some limitations, like inconsistent quality and size availability.
If you're looking for a more robust solution, you might want to check out FaviconExtractor (faviconextractor.com). It offers multiple sizes (16x16 to 512x512), works with most websites, auto-generates SVGs when needed, and provides ready-to-use HTML snippets. It's designed to handle cases where Google's API might fall short.
FaviconExtractor also supports DuckDuckGo as a fallback source, ensuring higher success rates. It's open-source (github.com/seadfeng/favicon-downlo...) and can be self-hosted or used via API.
While Google's hidden API is handy, tools like FaviconExtractor can offer more comprehensive solutions for developers needing reliable favicon extraction. Have you encountered any specific challenges with favicon retrieval in your projects?