Home > Articles

Adding Text and More

  • Print
  • + Share This
This chapter is from the book

English Isn't the Only Language

You can use HTML even if you don't write in English. URLs, hyperlinks, HTML tags, and document formatting elements are language neutral, but text requires a specification all its own. If you write in standard U.S. English, you don't need to make any changes to the way you create your HTML documents. If you are writing text in any other language, however, you should specify the language for the browser. The following HTML samples show the designations for German and French.

<html xmlns="http://www.w3.org/1999/xhtml"
       xml:lang="de" lang="de">


<html xmlns="http://www.w3.org/1999/xhtml"
       xml:lang="fr" lang="fr">

The language attributes (xml:lang and lang) support the same values as ISO, the International Standards Organization. You can see the full list of supported languages and their codes at www.loc.gov/standards/iso639-2/langcodes.html.

Mixing Languages in a Single Page

Although the preceding example shows the lang attribute used as part of the <html> tag at the top of your document, it's possible that you would want to include text of one language within a document of another language—for example, including a paragraph in French within a document in English. You can assign the lang attribute to the <p> tag to solve this problem. Look at the following sample:

<!DOCTYPE html
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml"
       xml:lang="en" lang="en">
<title>Multi-Language Document</title>
<p>Put your English text here.</p>
<p lang="fr">Mettez votre texte français ici.</p>
<p lang="en">Put the rest of your English text here.</p>
  • + Share This
  • 🔖 Save To Your Account