Always include the lang attribute inside the <html> tag to declare the primary language of your webpage. This attribute helps search engines (like Google) categorize your site and helps screen readers pronounce content correctly for visually impaired users.
In HTML5, the declaration is very simple and goes at the very top of your document.
If you are working with older XHTML documents, the language must be declared twice (for both XML and HTML compatibility).
ISO 639-1 provides standard two-letter codes for most languages. Here are the most common ones you might use on LearnHTML:
| Language | Code | Language | Code |
|---|---|---|---|
| English | en | Urdu | ur |
| Spanish | es | Hindi | hi |
| French | fr | Arabic | ar |
| Chinese | zh | German | de |
| Russian | ru | Japanese | ja |
Sometimes, you need to be more specific. You can add a country code to the language code to specify a regional dialect (e.g., Language-Country).