This is a part of very old discussion yet most of us find problems in adding Hindi lines to a website. But after reading this blog, you won’t find it difficult to write any language in a website.
The reason for Hindi’s strange behavior
We can’t add Hindi just like English because Hindi letters needs more than 1 byte to encode. All English letters and symbols are among the first 128 characters of the Unicode character set that needs 1 byte encoding. Next 1920 characters are of languages like Chinese, Arabic, and Greek that require 2 bytes to encode. Letters and symbols of other languages including Hindi need 3 to 4 bytes to encode.
English letters can be encoded using any encoding scheme (ASCII, , UCS-2, UTF-8 etc), but Hindi and other Indian languages must be encoded in UTF-8 to become readable for web languages (php, html, js etc) since they are outside the 128 character mark and need more than 1 byte to encode.
Not only Hindi, other languages like Chinese, Japanese, Thai, French all must be encoded in UTF-8.
Add Hindi by encoding charcters in UTF-8
By default, we use a text editors like notepad or notepad++ to write codes. For adding Hindi/Kannada or any language, just change the encoding from ANSI to UTF-8 as shown in the image below. Next compile the code and run the page.
You should see the Hindi text displaying on the webpage. In the same way, you can develop an entire site in Hindi.
One thing to note here is that, you must specify a Hindi font name for the text. One font could be ‘Mangal’ that comes default in windows.
Here is a quick stepwise instructions on adding Hindi in websites.
- Write Hindi content in MS Word.
- Set encoding of text editor to UTF-8.
- Add Hindi text to the webpage just like English text. Also set the font name as ‘Mangal’.
<p style=’font-family: Mangal’> hindi text </p>
- Save the webage and run.
- That’s all! You should see your Hindi text on the page.
This works on all browser and there is no compatibility issue. By changing the encoding and setting the right font, we can write Hindi, Gujarati, Chinese or any other language in a website.