The favicon is the smallest file on a website and one of the easiest to break. A theme update renames it. A page builder adds its own <link rel="icon"> on some templates. Someone uploads the logo as the icon, and it is a wide rectangle. A media library clean-up deletes the file, and the CMS starts returning its "page not found" HTML with a 200 status at the icon URL. Nobody notices, because the browser tab still shows something from cache.

The icon also matters outside the browser tab. Google can show a site's favicon next to its results, and it reads that icon from the home page. If the home page points at a missing file, the result shows a generic globe instead of the client's logo.

This tutorial builds a small Python script, standard library only, that reads a sitemap, fetches every page and reports:

  • pages with no rel="icon" link (and a home page with none, which is worse),
  • icon links that return an error status,
  • icon URLs that return something that is not an image, such as an HTML error page with status 200,
  • icons that are not square, and icons smaller than 48x48,
  • pages that only offer an SVG icon with no PNG or ICO fallback,
  • pages whose icon links differ from the home page,
  • the size and format of /favicon.ico, the file browsers fall back to,
  • a web app manifest that is not valid JSON, has no icons, or has no 192x192 or 512x512 icon.

It reads image sizes straight from the file headers (PNG, GIF, ICO, BMP, JPEG), so it needs no imaging library.

I ran it for real against a small fictional site on localhost, so every line of output below is real output from the script. The site, "Maple Street Bakery", is made up for this tutorial, and all its icon files are generated by the fixture server.

Disclosure: I work on Appie.run. Two free sitemap tools on appie.run are mentioned near the end; the script does not need them.

What Google says about favicons

Google's Search Central page "Define a favicon to show in search results" (read 5 Dec 2026, page marked last updated 27 Oct 2026) sets out the rules this script checks against. The parts that matter here:

  • Add a <link> tag to the header of your home page. Google supports rel values icon, shortcut icon, apple-touch-icon and apple-touch-icon-precomposed.
  • Google supports one favicon per hostname. A subdirectory cannot have its own.
  • Googlebot must be able to crawl the home page, and Googlebot-Image must be able to crawl the favicon file.
  • The favicon must be square (1:1) and at least 8x8px. Google recommends using one larger than 48x48px.
  • Supported formats: BMP, GIF, ICO, PNG, JPEG, PPM and TIFF. SVG is not in that list, which is why the script asks for a PNG or ICO fallback when a page only offers SVG.
  • The favicon URL should be stable.

The page also says a favicon is not guaranteed to appear even when every guideline is met. The script can tell you whether the basics are in place; it cannot tell you what Google will show.

Inner pages do not affect the search favicon, but they still matter to people: the icon in the browser tab and in bookmarks comes from the page they are on. That is why the script checks every URL in the sitemap and not only the home page.

What the script does not do

  • It does not check robots.txt. If you want that too, our earlier post on canonical and noindex checks uses urllib.robotparser; the same few lines work here for the icon URLs.
  • It reads the HTML the server sends. Icon links added by JavaScript are invisible to it.
  • It does not judge whether the icon looks like the client's brand. Open the files and look.
  • It reads sizes from headers. For an ICO file it reports the largest image inside.

The fixture site

The fictional bakery site has five pages: home, menu, about, one blog post and contact. The "before" version has these problems, each a common way icons break on small business sites:

  • the home page links /icons/favicon-old.png, which no longer exists (404),
  • the menu page has no icon link at all,
  • the about page uses rel="shortcut icon" on a 64x40 logo, which is not square,
  • the blog post links an icon under /wp-content/uploads/ that now returns an HTML "page not found" page with status 200,
  • the contact page offers only an SVG icon (plus a correct apple-touch-icon),
  • /favicon.ico is a 16x16 icon,
  • the web app manifest has a trailing comma, so it is not valid JSON.

The "after" version links the same 96x96 PNG, a 180x180 apple-touch-icon and a valid manifest (192x192 and 512x512 icons) on every page, and /favicon.ico is 48x48.

The fixture is a tiny http.server app on port 8506 that serves a sitemap, the five pages and the icon files. It takes before or after as its argument.

The script

Save this as favicon_audit.py. It needs Python 3.8 or later and nothing outside the standard library.

#!/usr/bin/env python3 """Audit favicons, apple-touch-icons and the web app manifest across a sitemap (stdlib only). Usage: python3 favicon_audit.py https://example.com/sitemap.xml [--csv report.csv] Exit code 1 if any error is found. """ import argparse, csv, json, struct, sys import xml.etree.ElementTree as ET from html.parser import HTMLParser from urllib.error import HTTPError, URLError from urllib.parse import urljoin, urlsplit from urllib.request import Request, urlopen UA = "favicon-audit/1.0 (+stdlib script)" NS = "{http://www.sitemaps.org/schemas/sitemap/0.9}" # Formats listed on Google's "Define a favicon to show in search results" page. GOOGLE_FORMATS = {"bmp", "gif", "ico", "png", "jpeg", "ppm", "tiff"} def fetch(url, limit=2_000_000): req = Request(url, headers={"User-Agent": UA}) try: with urlopen(req, timeout=15) as r: return r.status, r.headers.get("Content-Type", ""), r.read(limit), r.geturl() except HTTPError as e: return e.code, e.headers.get("Content-Type", ""), b"", url except URLError as e: return None, "", str(e.reason).encode(), url def sitemap_urls(url): status, _, body, _ = fetch(url, 20_000_000) if status != 200: sys.exit(f"Could not read sitemap {url}: status {status}") root = ET.fromstring(body) if root.tag == NS + "sitemapindex": out = [] for loc in root.iter(NS + "loc"): out += sitemap_urls(loc.text.strip()) return out return [loc.text.strip() for loc in root.iter(NS + "loc")] class HeadLinks(HTMLParser): def __init__(self): super().__init__() self.links = [] # (rel tokens, href, sizes) def handle_starttag(self, tag, attrs): if tag != "link": return a = dict(attrs) rel = (a.get("rel") or "").lower().split() if a.get("href") and rel: self.links.append((rel, a["href"].strip(), a.get("sizes", ""))) def sniff(data): """Return (format, width, height) from the first bytes of an image, or (None, None, None).""" if data.startswith(b"\x89PNG\r\n\x1a\n") and len(data) >= 24: w, h = struct.unpack(">II", data[16:24]) return "png", w, h if data[:6] in (b"GIF87a", b"GIF89a"): w, h = struct.unpack("<HH", data[6:10]) return "gif", w, h if data[:4] == b"\x00\x00\x01\x00" and len(data) >= 6: count = struct.unpack("<H", data[4:6])[0] best = (0, 0) for i in range(count): off = 6 + 16 * i if len(data) < off + 16: break w, h = data[off] or 256, data[off + 1] or 256 best = max(best, (w, h)) return "ico", best[0], best[1] if data[:2] == b"BM" and len(data) >= 26: w, h = struct.unpack("<ii", data[18:26]) return "bmp", w, abs(h) if data[:2] == b"\xff\xd8": i = 2 while i + 9 < len(data): if data[i] != 0xFF: i += 1 continue marker = data[i + 1] if marker in (0xC0, 0xC1, 0xC2): h, w = struct.unpack(">HH", data[i + 5:i + 9]) return "jpeg", w, h seg = struct.unpack(">H", data[i + 2:i + 4])[0] i += 2 + seg return "jpeg", None, None head = data[:500].lstrip().lower() if head.startswith(b"<svg") or (head.startswith(b"<?xml") and b"<svg" in head): return "svg", None, None if data[:4] == b"RIFF" and data[8:12] == b"WEBP": return "webp", None, None return None, None, None def main(): ap = argparse.ArgumentParser() ap.add_argument("sitemap") ap.add_argument("--csv") args = ap.parse_args() findings = [] # (level, url, message) def add(level, url, msg): findings.append((level, url, msg)) pages = sitemap_urls(args.sitemap) origin = "{0.scheme}://{0.netloc}".format(urlsplit(pages[0])) home = origin + "/" print(f"Sitemap: {args.sitemap} ({len(pages)} URLs)\n") page_icons, page_touch, page_manifest = {}, {}, {} for url in pages: status, ctype, body, final = fetch(url) if status != 200 or "html" not in ctype: add("WARN", url, f"page not audited (status {status}, {ctype or 'no content-type'})") continue p = HeadLinks() p.feed(body.decode("utf-8", "replace")) page_icons[url] = [urljoin(final, h) for rel, h, _ in p.links if "icon" in rel] page_touch[url] = [urljoin(final, h) for rel, h, _ in p.links if "apple-touch-icon" in rel or "apple-touch-icon-precomposed" in rel] page_manifest[url] = [urljoin(final, h) for rel, h, _ in p.links if "manifest" in rel] # Check every distinct icon file once. cache = {} def check_icon(icon_url): if icon_url in cache: return cache[icon_url] status, ctype, body, _ = fetch(icon_url) fmt, w, h = sniff(body) if status == 200 else (None, None, None) cache[icon_url] = (status, ctype, fmt, w, h) return cache[icon_url] def describe(icon_url, where): status, ctype, fmt, w, h = check_icon(icon_url) if status != 200: add("ERROR", where, f"icon {icon_url} returns status {status}") return None if fmt is None: add("ERROR", where, f"icon {icon_url} is not an image (status 200, {ctype})") return None if w and h and w != h: add("ERROR", where, f"icon {icon_url} is {w}x{h}, not square") return fmt, w, h for url, icons in page_icons.items(): plain = icons for touch in page_touch[url]: res = describe(touch, url) if res and res[1] and res[1] < 180: add("WARN", url, f"apple-touch-icon {touch} is {res[1]}x{res[2]}; 180x180 is the usual size") if not plain: level = "ERROR" if url == home else "WARN" add(level, url, "no rel=icon link; browsers fall back to /favicon.ico" + (" and Google reads the icon from the home page" if url == home else "")) good_for_google = False for icon in icons: res = describe(icon, url) if not res: continue fmt, w, h = res if fmt in GOOGLE_FORMATS and (w is None or (w == h and w >= 8)): good_for_google = True if w and w == h and w < 48: add("WARN", url, f"icon {icon} is {w}x{h}; Google recommends larger than 48x48") if url == home and icons and not good_for_google: add("ERROR", url, "home page has no working square icon in a format Google lists " "(BMP, GIF, ICO, PNG, JPEG, PPM, TIFF)") if plain and not good_for_google and url != home: fmts = {check_icon(i)[2] for i in plain} if fmts <= {"svg", "webp"}: add("WARN", url, f"only {'/'.join(sorted(f for f in fmts if f))} icon offered; " "add a PNG or ICO fallback") home_set = set(page_icons.get(home, [])) for url, icons in page_icons.items(): if url != home and icons and set(icons) != home_set: add("WARN", url, "icon links differ from the home page") # /favicon.ico fallback fav = origin + "/favicon.ico" status, ctype, fmt, w, h = check_icon(fav) if status != 200 or fmt is None: add("WARN", fav, f"/favicon.ico fallback missing or not an image (status {status})") else: add("INFO", fav, f"/favicon.ico fallback: {fmt} {w}x{h}") if w and w == h and w < 48: add("WARN", fav, f"/favicon.ico is only {w}x{h}") # Web app manifest(s) if home in page_touch and not page_touch[home]: add("WARN", home, "home page has no apple-touch-icon link") manifests = sorted({m for ms in page_manifest.values() for m in ms}) for m in manifests: status, ctype, body, _ = fetch(m) if status != 200: add("ERROR", Source:https://dev.to/appierun_66/audit-favicons-apple-touch-icons-and-the-web-app-manifest-across-your-sitemap-with-python-3566

Related posts