HTML
Der einfachste Weg: Lass ein <img>-Tag auf die API zeigen. Gib width und height an, um Layout-Verschiebungen zu vermeiden.
HTML
<img src="https://favicon.is/github.com" width="32" height="32" alt="GitHub" loading="lazy">
<!-- High resolution for retina screens -->
<img src="https://favicon.is/github.com?larger=true" width="64" height="64" alt="GitHub">Markdown
Zeige ein Website-Icon in README-Dateien, Dokus und Notizen.
Markdown
 [GitHub](https://github.com)CSS
Nutze das Icon als Hintergrundbild, zum Beispiel neben externen Links.
CSS
a[href^="https://github.com"]::before {
content: "";
display: inline-block;
width: 1em;
height: 1em;
margin-right: 0.35em;
vertical-align: -0.125em;
background: url("https://favicon.is/github.com?size=32") center / contain no-repeat;
}JavaScript
Ergänze zur Laufzeit alle externen Links auf einer Seite um Icons.
JavaScript
document.querySelectorAll('a[href^="http"]').forEach((link) => {
const { hostname } = new URL(link.href);
const icon = document.createElement('img');
icon.src = `https://favicon.is/${hostname}?size=32`;
icon.width = icon.height = 16;
icon.alt = '';
icon.loading = 'lazy';
icon.style.marginRight = '0.35em';
link.prepend(icon);
});React
Eine kleine wiederverwendbare Komponente mit Fallback, falls das Bild nicht lädt.
React
export function Favicon({ domain, size = 16 }) {
return (
<img
src={`https://favicon.is/${domain}?size=${size * 2}`}
width={size}
height={size}
alt=""
loading="lazy"
onError={(event) => {
event.currentTarget.src = 'https://favicon.is/default-favicon.svg';
}}
/>
);
}
// <Favicon domain="github.com" />Vue
Dieselbe Komponente als Vue-Single-File-Component.
Vue
<script setup>
defineProps({
domain: { type: String, required: true },
size: { type: Number, default: 16 },
});
</script>
<template>
<img
:src="`https://favicon.is/${domain}?size=${size * 2}`"
:width="size"
:height="size"
alt=""
loading="lazy"
/>
</template>Python
Lade Icons in einem Skript herunter, zum Beispiel für eine Lesezeichen-Seite.
Python
import pathlib
import urllib.request
domains = ["github.com", "wikipedia.org", "python.org"]
out = pathlib.Path("icons")
out.mkdir(exist_ok=True)
for domain in domains:
with urllib.request.urlopen(f"https://favicon.is/{domain}?larger=true") as response:
ext = {"image/png": "png", "image/x-icon": "ico", "image/svg+xml": "svg"}.get(
response.headers.get_content_type(), "img"
)
(out / f"{domain}.{ext}").write_bytes(response.read())
print(domain, response.headers["X-Source"])PHP
Rendere ein Icon in einem serverseitigen Template.
PHP
<?php
$domain = parse_url($link, PHP_URL_HOST);
$src = 'https://favicon.is/' . rawurlencode($domain) . '?size=32';
?>
<img src="<?= htmlspecialchars($src) ?>" width="16" height="16" alt="">Go
Rufe ein Icon ab und speichere es auf der Festplatte.
Go
package main
import (
"io"
"net/http"
"os"
)
func main() {
resp, err := http.Get("https://favicon.is/go.dev?larger=true")
if err != nil {
panic(err)
}
defer resp.Body.Close()
file, err := os.Create("go.dev.png")
if err != nil {
panic(err)
}
defer file.Close()
if _, err := io.Copy(file, resp.Body); err != nil {
panic(err)
}
}cURL
Prüfe die Response-Header über die Kommandozeile.
cURL
# Inspect the response headers
curl -I https://favicon.is/github.com
# Save a 64 px icon
curl -o github.png "https://favicon.is/github.com?size=64"