DEV Community

Cover image for Google API to Fetch Favicons for any domain
Simplr
Simplr

Posted on • Edited on • Originally published at blog.simplr.sh

2 1 1 1 1

Google API to Fetch Favicons for any domain

Use this unknown Google API to fetch the favicon image for any domain/subdomain with the ability to specify a custom size as well!

https://www.google.com/s2/favicons?domain=<domain_name>&sz=<size>
Enter fullscreen mode Exit fullscreen mode

Do not forget or remove the www part, the API doesn't work without it.

  1. Replace the <domain_name> with the domain/subdomain URL you wish to get the Favicon for.
  2. Replace the <size with a number in pixels you would like the image to be returned in.

By default the Favicon image returned is 16x16 pixels, the same applies if the specified size is not found or incorrect.

The API redirects you to a cached URL and response which make using it very fast as it is backed by Google's own world-leading CDN infrastructure.

For Example:

https://www.google.com/s2/favicons?domain=jsdelivr.com&sz=64
Enter fullscreen mode Exit fullscreen mode

Redirects you to the URL https://t1.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://jsdelivr.com&size=64 which displays the following Favicon image

jsDelivr Favicon

If a favicon for the domain is not found, it returns a weird image probably not suitable to be displayed or used anywhere so someway of finding a fallback path would be nice.

Favicon Not Found image:
Image description

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay