jQuery :lang() Selector

Beginner
6 min read
Updated: Oct 2026
5 examples
Live preview

What Is :lang()?

:lang(language) (since jQuery 1.9) selects elements whose language matches the given code — equal to it, or starting with that code plus a hyphen (so :lang(en) matches en and en-US, but not english). Language usually comes from the lang attribute (and can inherit from ancestors).

Remember
$("div:lang(en)")          // lang="en", "en-US", "en-GB", …
$("div:lang(en-us)")       // en-us specifically (official demo)
$("p:lang(es)")            // Spanish paragraphs
$('[lang="en"]')           // exact attribute only — narrower!

// Inheritance: a child without lang= still matches
// if an ancestor sets the language
NeedUse
Any English content$(":lang(en)")
US English only$(":lang(en-us)")
Exact attribute value$('[lang="en"]')
Divs in Spanish$("div:lang(es)")
Native CSSdocument.querySelectorAll(":lang(en)")

How to Use :lang()

Pass a language code, optionally prefix with a tag, then style or count matches.

  1. Write $(":lang(en)") or $("div:lang(en-us)").
  2. Use a short code (en) to catch regional variants (en-US, en-GB).
  3. Use a full tag (en-us) when you need one region only.
  4. Remember descendants inherit language from ancestors without their own lang.
  5. Prefer :lang() over [lang=…] when inheritance or prefix matching matters.
PieceRequired?Role
language argumentYesLanguage code such as en, en-us, es
Tag prefixOptionalLimits matches to one element type (div:lang(…))
lang attributeOn treeSets language on the element or an ancestor
Return value—jQuery collection of matching elements (may be empty)

Pseudocode

Pseudocode
matches = []
for each element in search context:
    lang = resolved language of element
           (own lang=, or inherited from ancestor)
    if lang equals code
       or lang starts with code + "-":
        matches.add(element)

return matches

// :lang(en)  → en, en-US, en-GB
// :lang(en)  ✗ english  (no hyphen after "en")

Cheat Sheet

Keep these facts handy while matching by language.

TopicDetail
Syntax$(":lang(language)")
SincejQuery 1.9 · standard CSS
Prefix ruleen matches en-US
InheritanceChildren inherit ancestor language
vs [lang]Attribute = exact value, no inherit
Official demodiv:lang(en-us) / div:lang(es-es)
CaseLanguage codes are case-insensitive
Native CSSYes — works in querySelectorAll

Live Preview

Run different language selectors against a small multilingual sample and see how many elements match.

Sample includes nested en-us / es-es divs (official style) plus lang="en" and lang="fr" paragraphs.

Result
$("div:lang(en-us)")
matched: 3

/* parent + two children inherit en-us */

jQuery Examples

Short, copy-ready snippets. Open DevTools Console with jQuery loaded, or use Try It Yourself for a live editor.

Example 1 — Official Demo: div:lang(en-us) / es-es

Mark USA and Spain blocks by language (jQuery API example, CSS-free).

jQuery
$("div:lang(en-us)").attr("data-region", "usa");
$("div:lang(es-es)").attr("data-region", "spain");

$("#out").text(
  "en-us: " + $("div:lang(en-us)").length +
  " · es-es: " + $("div:lang(es-es)").length
);
Try It Yourself

How It Works

  1. Select. div:lang(en-us) finds every div with that language.
  2. Inherit. Nested divs without lang still match the parent.
  3. Mark. data-region labels each matched block.
  4. Count. Spain blocks are selected the same way with es-es.

Example 2 — Prefix Match: :lang(en) vs :lang(en-us)

Short codes catch regional variants; full tags stay specific.

jQuery
console.log(":lang(en) →", $("div:lang(en)").length);
console.log(":lang(en-us) →", $("div:lang(en-us)").length);
console.log(":lang(en-gb) →", $("div:lang(en-gb)").length);
Try It Yourself

How It Works

  1. Prefix. :lang(en) matches en, en-us, and en-gb.
  2. Specific. :lang(en-us) matches only the US tag.
  3. Other region. en-gb is separate from en-us.
  4. Rule. Match needs equality or code- prefix — not english.

Example 3 — :lang(fr) vs [lang="fr"]

Attribute equality is exact and does not inherit; :lang() does both.

jQuery
console.log(":lang(fr) →", $("*:lang(fr)").length);
console.log('[lang="fr"] →', $('[lang="fr"]').length);
Try It Yourself

How It Works

  1. Pseudo. :lang(fr) uses resolved language (including inheritance).
  2. Attribute. [lang="fr"] needs that exact attribute on the element.
  3. Gap. A child without lang matches :lang but not [lang].
  4. Choose. Use :lang() for language-aware UI; use [lang] for exact markup checks.

Example 4 — Language Inheritance

Set lang on a parent; children without lang still match.

jQuery
$("div:lang(ja) span").each(function () {
  this.appendChild(document.createTextNode(" [ja]"));
});

$("#out").text("Matched spans: " + $("div:lang(ja) span").length);
Try It Yourself

How It Works

  1. Parent. lang="ja" on the wrapper sets the language context.
  2. Children. Spans with no lang inherit that value.
  3. Select. div:lang(ja) span finds those inherited spans.
  4. Mark. Appending [ja] makes inheritance visible.

Example 5 — Tag Scope: article:lang(de)

Prefix with a tag so only articles in that language match.

jQuery
$("article:lang(de)").each(function () {
  this.insertBefore(document.createTextNode("[DE] "), this.firstChild);
});

$("#out").text("German articles: " + $("article:lang(de)").length);
Try It Yourself

How It Works

  1. Tag. article limits the search to article elements.
  2. Language. :lang(de) keeps German content only.
  3. Other tags. A German p elsewhere is ignored.
  4. Label. Prepending [DE] shows which article matched.

Edge Cases & Pitfalls

Check these before relying on :lang() in multilingual pages.

prefix

:lang(en) ≠ the word “english”

Matching needs equality or a hyphen suffix (en-US). lang="english" does not match.

inherit

Children inherit language

A nested element without lang still matches if an ancestor sets the language.

attr

[lang="en"] is narrower

Exact attribute only — no prefix match, no inheritance. Prefer :lang(en) for language-aware selection.

version

Needs jQuery 1.9+

:lang() was added in jQuery 1.9. Older builds will not recognize it.

Browser Support

The :lang() pseudo-class is standard CSS and has been available in jQuery since 1.9. Modern browsers also support it in native querySelectorAll(":lang(en)").

✓ jQuery 1.9+ · CSS standard

jQuery :lang() Selector

Supported in jQuery 1.9+ and native CSS across modern browsers. Prefer :lang() for inheritance and prefix matching; use [lang] for exact attributes.

100% CSS + jQuery 1.9+
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
:lang() Universal (modern)

Bottom line: Safe in jQuery 1.9+ and modern browsers. Use short codes for language families; full tags for one region.

Performance Notes

ApproachCostBest for
$("div:lang(en)")FastTag-scoped language match (native CSS)
$("#main :lang(en)")CheaperLarge pages — limit the search root
$(":lang(en)")OKSmall documents
$('[lang^="en"]')DifferentExact attributes only — no inheritance

Because :lang() is standard CSS, modern browsers can run it via querySelectorAll. Scope with a tag or container when the DOM is large.

Key Takeaways

  • Role: select elements by resolved language code.
  • Prefix: :lang(en) matches en and en-US.
  • Inherit: children without lang still match ancestors.
  • vs attr: [lang] is exact — no prefix, no inheritance.

One line: $(":lang(en)") finds English content — including en-US and inherited language — while [lang="en"] is exact-only.

Frequently Asked Questions

:lang(language) selects elements whose language matches the supplied language code. $("div:lang(en)") matches lang="en" or lang="en-US" (code plus hyphen suffix), but not unrelated values like lang="english". Available since jQuery 1.9.
[lang="en"] matches only an exact lang attribute on that element. :lang(en) also matches lang="en-US", lang="en-GB", and elements that inherit language from an ancestor with a matching lang value.
Yes. :lang() is defined in the W3C CSS specification. It works in jQuery 1.9+ and in native querySelectorAll(":lang(en)") in modern browsers.
For HTML, language comes from the lang attribute on the element or ancestors, and possibly from meta elements or HTTP headers — as described in the official jQuery documentation.
Official jQuery demo runs $("div:lang(en-us)").addClass("usa") and $("div:lang(es-es)").addClass("spain") to style USA and Spain content blocks by language.
Yes. :lang(en) matches both lang="en" and lang="en-US" because en-US starts with en followed by a hyphen. Use :lang(en-us) when you need that regional tag only.

Next: :contains() Selector

Learn how to select elements by their text content with :contains().

:contains() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful