I shared a link to one of my tool pages on Quora and the preview card looked like this:
HEIC to JPG Converter ŌĆ– Convert HEIC to JPG Online Free
The page itself looked fine in every browser. The title in the HTML was correct. Only the preview was broken. If you've ever seen –, ’ or ŌĆ– in place of a dash or apostrophe, this is the same bug, and it's worth five minutes to understand.
What actually happened
The title contains an en dash: – (U+2013). In UTF-8 that character is three bytes:
E2 80 93 If something reads those three bytes with a single-byte encoding instead of UTF-8, each byte becomes its own character. In Windows-1252 they become –. In other single-byte code pages you get different garbage, like the ŌĆ– I saw. Same bug, different wrong decoder.
So the question was: why would a crawler decode my page as anything other than UTF-8?
The two places a charset can come from
A browser or crawler decides the encoding from, roughly in this order:
- The
Content-TypeHTTP header, e.g.text/html; charset=utf-8 - A
<meta charset="utf-8">tag near the top of the HTML - Guessing
My pages had the meta tag as the very first thing in <head>. Browsers are happy with that. But the server was sending:
Content-Type: text/html No charset. You can check your own site from the browser console:
const r = await fetch(location.href, { cache: 'no-store' }); r.headers.get('content-type'); // "text/html" means no charset is sent Some link-preview fetchers don't parse the HTML deeply enough to find the meta tag, or they only read the first chunk of bytes and then fall back to a default. With no header to go on, they guessed, and they guessed wrong.
The fix (Apache / shared hosting)
My site is static HTML on shared hosting running Apache, so the fix is two lines in .htaccess:
AddDefaultCharset UTF-8 AddCharset UTF-8 .html .xml .txt .css .js AddDefaultCharset adds charset=UTF-8 to text/html and text/plain responses. AddCharset covers the other text types by extension, so the sitemap, CSS and JavaScript get it too.
On Nginx, the equivalent is:
charset utf-8; charset_types text/html text/xml text/plain text/css application/javascript application/xml; After deploying, the header becomes text/html; charset=UTF-8 and every client gets the right answer without guessing.
Keep the meta tag anyway
The header doesn't replace <meta charset="utf-8">. Keep both:
- The meta tag still matters when someone saves the page to disk and opens it later, because there's no HTTP header then.
- It must be within the first 1024 bytes of the document, so put it before anything else in
<head>, including long inline scripts or comments.
One gotcha: cached previews
Fixing the header doesn't fix previews that were already generated. Facebook, LinkedIn and others cache link previews. Facebook's Sharing Debugger and LinkedIn's Post Inspector let you force a re-scrape. For other sites you may just have to wait.
The takeaway
If your page looks right in the browser but wrong in a preview, a feed reader or someone else's scraper, check the Content-Type header first. A missing charset is an easy thing to overlook on static hosting, because browsers quietly cover for it.
I found this one while sharing pages from 14FreeTools, a set of free browser-based image and PDF tools I'm building. It's the kind of bug you only notice when you look at your site through someone else's eyes.