A fresh HTML document is where your new website starts. It doesn’t look like much. In fact it’s blank.
Maybe except for DOCTYPE and Charset.
Someone on the web might have told you to put it in the beginning of your HTML document. You may have read somewhere that it’s important.
You shrug and put it in, because why not.
But you don’t really get why why you have to.
Let’s find out,
The web is worldwide with thousands of different languages. You have to disclose what character encoding you use in your website. Otherwise your website might be unavailable to millions of people. Unavailable isn’t a good look on the web. In fact, it tends to drive people away.
Say Sigfried is sitting in Denmark and he has just written a killer blog post about his cute puppy who every day tries to eat the windscreen wipers in his car. The puppy snaps and barks at the wipers, but no matter how hard he tries, he simply cannot seem to overcome the barrier of the windscreen and get at those wipers. Sigfried writes the story in English, because he wants to reach as many people as possible. But he forgets one important thing.
You find Sigfried’s blog post and you want to read it. But lo and behold, Sigfried hasn’t used Charset UTF-8. Sigfried’s dog is called “Søren”. So every time Søren’s name is mentioned, all you see is a weird combination of characters. Unless you want to deal with this annoyance, you now have to find another way to get mushy about puppies.
Well, you might think, my blog is only in English and for an English speaking audience. But if your charset encoding isn’t declared, you can still get in trouble with search engines and browsers.
Even small communities are diverse. Your commenters might have non Latin characters in their names, or you might have to quote the German song title “Entzünde mein Feuer”. Just saying. That’s why you should aim to make your content as available as possible.
If you are interested in the nitty-gritty of charset encoding, I recommend you read What every programmer absolutely, positively needs to know about encodings and character sets to work with text.