Language Codes
HTML Language Codes
Language codes are used in HTML to specify the language and regional variations of web content. This helps browsers, search engines, and assistive technologies interpret the content correctly.
Types of Language Codes
ISO 639
– Represents general language codes (e.g.,en
for English,fr
for French).ISO 3166
– Defines country-specific language variations (e.g.,en-US
for American English,fr-CA
for Canadian French).
Specifying Language in HTML
The lang
attribute tells browsers and screen readers the language of an element’s content. While it's often set in the <html>
tag, it can also be used on paragraphs
, divs
, or spans
for multilingual sections.
Declaring a Document's Language
This page is in English.
<h1>Welcome!</h1>
<p>This page is in English.</p>
Defining Multiple Languages in a Page
For multilingual pages, assign the lang
attribute to different sections:
Bonjour le monde
Hola Mundo
Hallo Welt
<h1>Hello World</h1>
<p lang="fr">Bonjour le monde</p> <!-- French -->
<p lang="es">Hola Mundo</p> <!-- Spanish -->
<p lang="de">Hallo Welt</p> <!-- German -->
Common Language Codes
Standard Language Codes (ISO 639)
en
– Englishfr
– Frenchde
– German
Regional Language Variants (ISO 3166)
en-US
– English (United States)fr-CA
– French (Canada)es-MX
– Spanish (Mexico)
lang
Attribute Benefits of Using the
- Improves accessibility – Helps screen readers pronounce content correctly.
- Enhances search optimization – Assists search engines in serving region-appropriate content.
- Supports formatting adjustments – Some browsers apply language-specific text styling.
Conclusion
HTML language codes, defined by the lang
attribute, specify the language and regional variations of content to ensure proper interpretation by browsers and assistive technologies. Using the lang
attribute enhances accessibility, search optimization, and formatting adjustments.
Lists
HTML organizes content using <ul> for unordered lists, <ol> for ordered lists, and <dl> for definition lists, improving clarity and structure.
Button
HTML buttons, created using <button> or <input type="button">, serve as interactive controls that initiate actions or submit forms. They can be customized with text, icons, or images, playing a vital role in user interaction.