For authors maintaining a personal index of foreign-language resources, correctly declaring the document's language is essential for accessibility and styling. This article outlines how to use the lang attribute on the html element and explains why this method is preferred over meta tags or HTTP headers for static indexes.

Setting Up Your Bilingual Index

Imagine a hypothetical author preparing a small public index of foreign-language readings. She has three saved items and writes them into a plain list, each with a title and one language marker. I’ll use her made-up entries to show why the label needs a clear scope before any index markup is written.

Her working entries might read: “Chambre claire — note de lecture (fr)”, “Deutschland 1918–1933 — Aufsatz (de)”, and “京都の町家 — 調査メモ (ja)”. These titles are her own drafting notes, not documents taken from anywhere, and the parenthetical tags are simply how she records the original language. One choice remains open: whether the marker should describe the whole linked document, the surrounding summary she typed, or both when those differ. Until she decides, a reader seeing “(fr)” beside an English gloss cannot tell which part is French.

A second open point is how to treat mixed material. Suppose one saved item has a German main article and an English abstract, and another is a Japanese scan with an English Contents list. A single letter tag hides that split. She might note the dominant language first and add the secondary language in a short phrase, but she has not settled on the order or the separator. The spellings fr, de, and ja shown here are her own abbreviations; I’m not assuming any particular lookup field or registry will accept them. Nor does her list yet show a destination for each entry, so no recipient or channel should be inferred from the labels.

A third item of uncertainty is the display language of her own interface. If her index pages are in English while documents are in French, German, or Japanese, then the page language and each document’s original language are separate facts and deserve separate fields. She sketches one field for the index page and one per entry, but leaves both blank for now. The next step is to fix that distinction in a written rule, then apply it consistently when she later prepares the actual page markup.

Using the lang Attribute on the html Element

The page-level step is to add a lang attribute to the html element, as in html lang="en", so browsers and other applications know the default language of the page. The tutorial states that language information supports accessibility, styling, and searching, and that browsers can use it to present content appropriately.1

Where the page is XHTML 1.x or an HTML5 polyglot document served as XML, the same value should also appear in an xml:lang attribute; a page served only as XML uses just xml:lang. The tutorial advises against a meta element with http-equiv set to Content-Language, and says tag values should come from the IANA Subtag Registry and follow BCP 47 syntax, kept as short as possible.1

For a document containing both the interface and the saved entries, you can decide the label’s scope before writing any markup. A practical first move is to sketch two candidate versions of the same page and compare them. In version one, the opening element carries a single declared language for the whole document, and each saved entry sits inside a wrapper element with the lang attribute set to its own value. In version two, the same three entries are written without any per-entry wrapper, so each item inherits the document’s declared language. You might paste both sketches side by side and check whether a reader can still tell that “京都の町家 — 調査メモ” is Japanese rather than a French document with a Japanese title.

The trade-off is legibility versus simplicity. Version two is shorter, but every entry inherits one language, so a screen reader or a dictionary extension may pronounce or suggest the wrong language for two of the three items. Version one adds one wrapper per item, which is more text to edit but lets each entry state its own language independently. If your index holds only one language besides English, version two may be enough; if entries mix French, German, and Japanese, the per-entry wrapper is the safer choice.

Before you commit, you can ask yourself what happens at a boundary. Does an English abstract inside a German entry need its own wrapper, or is the entry-level label sufficient? Whichever you pick, write the choice into your own working note for that entry so the next edit doesn’t silently change the scope.

For text-processing needs, the W3C draft recommends declaring language with attributes on the html element, setting a default for the whole document, and on any element whose content is in a different language. A meta element with http-equiv set to Content-Language is described as metadata about the intended audience of the whole document; it does not identify the language of a specific range of text. The draft notes that such audience metadata may be used for searching, serving the right language version, and classification, but is not specific enough to support text-processing. For an index whose entries switch between French, German, and Japanese, an entry-level meta declaration therefore would not attach the label to that entry's text; that requires the attribute approach.2

You can treat each saved item as a small unit and decide where its language declaration belongs. For her three made-up entries, she might begin with a plain list where each title sits inside its own block. If one entry is “Chambre claire — note de lecture (fr)” and another is “Deutschland 1918–1933 — Aufsatz (de)”, she can consider a short inline span around the title text only, carrying the language. That keeps a French title and a German title readable in one shared list while marking each separately.

A simpler alternative is one section per language, with the language set once on the section container and no span on every title. She might try this first because it needs fewer changes and makes her page easier to scan. The trade-off is that a single Japanese title inside the German section would inherit German unless she adds a span there. She can note that exception before writing, then choose either per-entry spans everywhere or section-level labels plus exceptions.

For mixed material, she can decide that an English abstract inside a German entry gets its own span if it will be quoted at length; otherwise, the entry-level label describes the main document. She can mark this as a working assumption and revisit it when the abstract is added, rather than trying to settle every boundary in advance.

Understanding Inheritance in Language Declarations

In the language-tag guidance from the W3C, inheritance works this way: language information is inherited by elements inside the one where the declaration was made, unless one of those elements declares a different language. On your index, a list set to one language would pass that language down to each entry, so an entry in another language needs its own declaration to override it.3

The same guidance notes that HTML and XML provide a means to prevent inheritance using the empty string, written as xml:lang="". In essence this says that no language should be associated with that information.3

For the three-entry example, you can now choose where inheritance begins. A workable next move is to sketch two candidate layouts on paper and compare them with your own titles. In the first, you place a language attribute on the list container for the dominant language of the page, then add a short inline element around any title written in another language. In the second, you split the list into three blocks, one per language, and declare the language once on each block. Neither sketch needs to be final; it is there to show how far one label reaches.

Consider what each choice costs you in upkeep. The container approach keeps her plain list intact, but when she later adds a fourth entry in a different language, she must remember to wrap its title. The sectioned approach makes that fourth entry obvious, because she adds it to the matching block, yet it fragments a reading order she may prefer chronological. You can pick whichever matches how you actually file material, and note the reason beside your draft.

You might also test a boundary case with the German entry that carries a short English abstract. Decide whether the abstract stays under the entry label or gets its own small wrapper; record that decision so a later addition follows the same pattern.

Choosing Correct Subtags from the IANA Registry

Use the IANA Language Subtag Registry to look up each subtag rather than working from ISO code lists. The registry is a long text file, and to find a language subtag you search the page for the language’s English name. Searching for “French” returns a record whose type is language and whose Subtag field is fr. To build fr-CA, you then search for Canada and check that the record’s type is region.3

The registry also shows fields that affect your choice: entries may carry Suppress-Script, and some are marked as redundant or deprecated. The page advises avoiding redundant or deprecated subtags and notes that variant subtags must be used in combination with certain other prescribed subtags. It also points to an unofficial, user-friendly search tool and to separate step-by-step guidance on choosing a language tag.3

When you are ready to refine her made-up French, German, and Japanese markers, the next move is a small revision pass rather than a page rewrite. You might open the IANA language subtag registry, keep the search box available, and check each candidate code against the entry it already has, so the plain list stays intact while you confirm spelling and scope.

As a hypothetical demonstration, her first draft could use the short labels “fr”, “de”, and “ja”. If she finds that a primary language subtag alone is too broad for a regional reading, she can consider a longer registered combination and compare how it reads beside the title. The choice remains hers: the shorter tag is easier to scan, while the longer one may better match the material she actually saved.

For a boundary case, you can record the question “does this code identify the document’s main language, or only a passage?” beside the entry, then check the registry’s description before changing anything. Mark what you verified and the date you checked it. If a code is missing from the registry, leave the marker unresolved rather than guessing, and note the next source you intend to inspect.

You can make the last pass concrete by revising the marker text for the three made-up entries before you touch the surrounding list. Start with the existing draft labels “(fr)”, “(de)”, and “(ja)” and ask a single question of each: would a reader who does not know the language still understand what this marker is telling them? If not, you might expand the parenthesis to a short word such as “French original”, “German original”, or “Japanese original”. This is a hypothetical edit, not a report of reader feedback, but it lets you compare the two versions side by side and decide which reads more naturally next to a title like “Chambre claire — note de lecture”.

A second revision move concerns consistency across the list. If one entry says “French original” and another says only “(de)”, the index looks unfinished even when both are correct. You can choose one style and apply it to all three entries, then reread the list as a whole. A short, uniform marker after every title usually scans better than a mix of long and short forms, though you may keep a longer form for an entry whose language is especially easy to misread.

For the German entry with a short English abstract, you might add a second, clearly separate marker rather than folding both languages into one parenthesis, so the main language stays obvious. Record this as a deliberate choice beside the entry, not as a rule you must follow elsewhere.

When you are unsure whether a marker is too vague, note the question next to that entry and check it against the actual saved document later. You can leave the entry in the list meanwhile, since an imperfect marker is easy to revise once you have confirmed the document’s main language.

Frequently asked questions

How might she record the original language of each saved item in a plain list?

Her working entries might read: “Chambre claire — note de lecture (fr)”, “Deutschland 1918–1933 — Aufsatz (de)”, and “京都の町家 — 調査メモ (ja)”. These titles are her own drafting notes, not documents taken from anywhere, and the parenthetical tags are simply how she records the original language.

What simpler layout could she try that sets the language once per section?

A simpler alternative is one section per language, with the language set once on the section container and no span on every title. She might try this first because it needs fewer changes and makes her page easier to scan.

How can she make a concrete last pass over the language markers for her three made-up entries?

You can make the last pass concrete by revising the marker text for the three made-up entries before you touch the surrounding list. Start with the existing draft labels “(fr)”, “(de)”, and “(ja)” and ask a single question of each: would a reader who does not know the language still understand what this marker is telling them?