Programmatically Get the Favicon Image for a Website
How can you get the favicon image for a website without manually pulling it from the web page code?
DuckDuckGo, Google, and Yandex have free services that pull the favicon image from a website for you.
Below is an example for each service to get Youtube's favicon image:
- DuckDuckGo: https://icons.duckduckgo.com/ip3/youtube.com.ico
- Google: https://www.google.com/s2/favicons?domain=youtube.com
- Yandex: https://favicon.yandex.net/favicon/youtube.com
All you need to do is replace youtube.com
in those URLs with the domain you want.
You could display these images directly into your web page with this HTML:
<img height="16" width="16" src="https://icons.duckduckgo.com/ip3/youtube.com.ico" />
<img height="16" width="16" src="https://www.google.com/s2/favicons?domain=youtube.com" />
<img height="16" width="16" src="https://favicon.yandex.net/favicon/youtube.com" />
Thanks for reading and happy coding!