Accessibility Tips
Techniques for improving web site accessibility.
The Language Attribute
Background
- The intent of the language, or lang, attribute is to allow user agents to render content more meaningfully based on accepted cultural practice for a given language.
Syntax
The syntax of lang tag is:
Language-Tag = Primary-tag *( "-" Subtag )
Primary-tag = 1*8ALPHA
Subtag = 1*8ALPHA
Examples:
<html lang="fr">(Parisian French/France)
<html lang="fr-FR">(Parisian French/France)
<html lang="fr-CA">(Canadian French)
<html lang="fr-BE">(Belgian French)
Usage
- Language information specified via the lang attribute may be used by a user agent to control rendering in a variety of ways. Some situations where author-supplied language information may be helpful include:
- Assisting search engines
- Assisting speech synthesizers
- Helping a user agent select glyph variants for high quality typography
- Helping a user agent choose a set of quotation marks
- Helping a user agent make decisions about hyphenation, ligatures, and spacing
- Assisting spell checkers and grammar checkers
Application
- It is most commonly applied to the page as a whole via the html tag, for example:
<html lang="en"> It can also be applied to other tags such as:
<span> <div> <p> <q> <a>It cannot be used on the following elements:
<applet> <base> <basefont> <br> <frame> <frameset> <iframe> <param> <script>
Examples
HTML 4.01
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="fr"> <head> <title>Un document multilingue</title> </head> <body> ...Interpreted as French... <p lang="es">...Interpreted as Spanish...</p> <p>...Interpreted as French again...</p> <p>...French text interrupted by<em lang="ja">some Japanese</em>French begins here again...</p> </body> </html>XHTML 1.0
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="fr" xml:lang="fr"> <head> <title>document écrit en français</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> </head> <body> ...document écrit en français... </body> </html>XHTML 1.1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr"> <head> <title>document écrit en français</title> <meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" /> </head> <body> ...document écrit en français... </body> </html>
See also
Help
For assistance please contact Andrew Normand, Web Accessibility Program Leader
Email: anormand@unimelb.edu.au
Phone: +61 3 9035 4867