FAQ: What is the 'lang' attribute and why do I need it?

Suggestions to improve this FAQ, especially its bittiness, most welcome.
The main part of the FAQ was intended to be 'why'.

Thanks

Deborah

-----------------------------------------

Question

What are 'lang' attributes and why do I need them?


Answer

The 'lang' attribute contains information about the language(s) used in
the HTML page.

According to HTML 4.01 Specification W3C Recommendation 24 December 1999
(http://www.w3.org/TR/html401/struct/dirlang.html#h-8.1.3), this
information is used for:

- Assisting search engines 
- Assisting speech synthesizers and Braille translators
- 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 

Also:
- The lang tag is required by the Web Accessibility Initiative and some
governmental policies in some countries.
- The 'xml:lang' attribute is the standard way to identify language
information in XML.

The 'html' element should contain a lang attribute with the predominant
language of the page. 
For example, <html lang="pt">. The value of the lang attribute is
usually a two-letter country code. (FAQ: Two-letter or three-letter
language codes)

Where the language changes, that change should be clearly identified.
For example, <p lang="en">He viewed Deidre's predicament with a certain
amount of <span lang="de">Schadenfreude</span>.</p>

HTML and XML have different syntax. When serving XHTML as text/html, you
should use both the lang attribute and the xml:lang attribute in the
html element.
(http://www.w3.org/International/tutorials/tutorial-lang.html)

	eg: HTML: <html lang="fr-CA">
       XHTML 1.0 served as text/html: <html lang="zh-CN"
xml:lang="zh-CN" xmlns="http://www.w3.org/1999/xhtml">
       
For more information on language tagging mark-up, see
(http://www.w3.org/International/O-HTML-tags.html).

CSS2 uses the 'lang' attribute powerfully as a pseudo class.
(http://www.w3.org/International/questions/qa-css-lang.html).

Which tags? The attribute can be applied to any element except applet,
base, basefont, br, frame, frameset, iframe, param, or script.

A common use for meta is to specify keywords that a search engine may
use to improve the quality of search results. When several meta elements
provide language-dependent information about a document, search engines
may filter on the xml:lang attribute to display search results using the
language preferences of the user.
(http://www.w3.org/TR/2002/WD-xhtml2-20020805/mod-meta.html)

For example, 

<-- For speakers of US English -->
<meta name="keywords" lang="en-us" 
         content="vacation, Greece, sunshine"/>
<-- For speakers of British English -->
<meta name="keywords" lang="en" 
         content="holiday, Greece, sunshine"/>
<-- For speakers of French -->
<meta name="keywords" lang="fr" 
         content="vacances, Gr&egrave;ce, soleil"/>
         
The lang attribute should be specified for alt-attributes and
longdesc-attributes.         


Useful links

HTML 4.01 Specification W3C Recommendation 24 December 1999:
http://www.w3.org/TR/html401/struct/dirlang.html#h-8.1.3.
XHTML 2.0 W3C Working Draft 5 August 2002
http://www.w3.org/TR/2002/WD-xhtml2-20020805/mod-meta.html
Web Accessbility Initiative: lang attribute -
http://www.w3.org/TR/WCAG10/#gl-abbreviated-and-foreign
Tutorial: Language markup in XHTML and CSS (DRAFT):
http://www.w3.org/International/tutorials/tutorial-lang.html
FAQ: Styling using the lang attribute:
http://www.w3.org/International/questions/qa-css-lang.html
FAQ: Two-letter or three-letter language codes:
http://www.w3.org/International/questions/qa-lang-2or3.html



BBCi at http://www.bbc.co.uk/

This e-mail (and any attachments) is confidential and may contain
personal views which are not the views of the BBC unless specifically
stated.
If you have received it in error, please delete it from your system. 
Do not use, copy or disclose the information in any way nor act in
reliance on it and notify the sender immediately. Please note that the
BBC monitors e-mails sent or received. 
Further communication will signify your consent to this.

Received on Monday, 9 February 2004 12:24:35 UTC