What is UTF-8 in html head?

Harsh Vats on August 28, 2020

Do you see <meta charset="UTF-8"> in html heads. If you know what this charset does then don't read further but if you don't, you will learn something new.

When you write some text in your html code, to show exactly the same text, browser must know the charset of the document.

Let me make it easy for you. Just make an html file and add <meta charset="ISO-8859-1"> in your html head. So now we are using charset ISO-8859-1 which was used earlier before utf-8.

Now in your html file add <p>हर्ष</p>. "हर्ष" is my name written in hindi language(language spoken in India). Now open the file in your browser. What do you see?? hahaha... you see something like "जैसा". Why is this so?? This is because the charset "ISO-8859-1" does not support hindi characters. That's why instead of my name some random characters appear in the browser. However if you change your charset to "utf-8" it will show you exactly the same you wrote in your code.

"utf-8" is the default character encoding for html5, meaning even if you don't declare the charset, browser will consider utf-8.

I hope that now you have the confidence to answer to the question "What is utf-8 or charset?".

  • linkedin
  • facebook
  • twitter
Connect with me on LinkedIn
© 2021, Built by Harsh Vats