HTML language Attribute

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

Definition and Usage

The language attribute on <script> was an early way to name the scripting language (usually language="JavaScript"). Its values were never well standardized.

It is not lang (page/content language). For new work, omit language entirely, or use type for modules and non-JS script blocks.

Deprecated / obsolete.

Do not use language in new pages. The HTML Standard says omit it. Learn it only to read legacy HTML and migrate safely.

HTML Syntax

syntax.html
<script language=" JavaScript"> … </script>

Modern equivalent: <script>…</script> (no language), or <script type="module"> when you need modules.

Attribute Values

Historical values you may still see in old code:

ValueDescriptionTry it
JavaScript / javascriptLegacy “this is JS” hint. If present, HTML says it should match this string (ASCII case-insensitive) and has no useful effect — omit itTry it
Other stringsNever standardized; ignore in modern browsers when type is setTry it
(omit attribute)Correct today for classic scriptsTry it
Use type insteadModules, import maps, speculation rules, or data blocksTry it

Live Preview

Compare legacy markup with the modern form. The demo button runs either way — language does not change behavior.

markup style

Study the snippet. Prefer the modern form in real projects.

Snippet
<script language="JavaScript">
  // deprecated — omit in new code
</script>

Legacy: language is present but unused by modern engines.

HTML Examples

Short study snippets. Use Try It Yourself for a live editor. Prefer the modern patterns in production.

Example 1 — Recognize Legacy Markup

Old pages often wrote language="javascript". Scripts still run; the attribute is obsolete.

HTML
<!-- Deprecated — for study only -->
<button type="button" id="go">Click me</button>
<script language="javascript">
  document.getElementById("go").addEventListener("click", function () {
    alert("Script runs; language is ignored.");
  });
</script>
Try It Yourself

How It Works

  1. Old intent. Authors used language to say “this script is JavaScript.”
  2. Never standardized well. Unlike type, allowed values were fuzzy.
  3. Today. Engines treat classic scripts as JS without needing language.
  4. Action. When you see it, plan to delete the attribute.

Example 2 — Modern Replacement

Omit language. Use a plain <script>, or type="module" when you need ES modules.

HTML
<button type="button" id="demo">Run script</button>

<!-- Classic JS: no language, no type needed -->
<script>
  document.getElementById("demo").addEventListener("click", function () {
    alert("Modern scripts omit language.");
  });
</script>

<!-- Modules: use type, not language -->
<!-- <script type="module" src="app.js"></script> -->
Try It Yourself

How It Works

  1. Default is JavaScript. A classic <script> needs no language hint.
  2. Modules use type. type="module" (and related types) replace old language hacks.
  3. Spec advice. If you ever wrote language="JavaScript", delete it — same behavior.
  4. Keep loading attrs. Use src, defer, async as needed — not language.

Example 3 — language vs lang

Page language and script language are different jobs — only lang belongs on content.

HTML
<!-- Correct: natural language of the page -->
<html lang="en">
<body>
  <p>This document is English.</p>

  <!-- Correct: classic script with no language attribute -->
  <script>
    console.log(document.documentElement.lang); // "en"
  </script>
</body>
</html>

<!-- Wrong: do not use language for page language -->
<!-- <script language="en">...</script> -->
Try It Yourself

How It Works

  1. lang declares human language for accessibility and SEO.
  2. language was a scripting MIME-ish hint on <script> only.
  3. Never mix them. language="en" does not set page language.
  4. Read next. Study lang for real i18n needs.

Edge Cases & Pitfalls

Most mistakes are copying old tutorials or confusing language with lang.

obsolete

Authors should omit it

Even language="JavaScript" should be removed. It does not improve modern pages.

type

type wins

If a type attribute is present, language is ignored. Prefer type for non-classic scripts.

compare

Not page language

Use lang on <html> (and nested elements). Never use language for that.

migrate

Search-and-delete safely

Removing language="…" from classic scripts is usually a no-op fix. Keep src, defer, async, and type="module" intact.

js

Do not setAttribute("language", …)

Dynamic script injection should set src / textContent / type only — never resurrect language.

Browser Support

language is a legacy HTML attribute on <script>. Engines may still parse it for old pages, but it is obsolete for authors.

✓ Deprecated · Do not use

language

Recognized in legacy documents. New sites must omit it. Prefer plain script or the type attribute.

Legacy Compatibility only
Google Chrome Parses legacy; ignore for authors
Legacy*
Mozilla Firefox Parses legacy; ignore for authors
Legacy*
Apple Safari Parses legacy; ignore for authors
Legacy*
Microsoft Edge Parses legacy; ignore for authors
Legacy*
Opera Parses legacy; ignore for authors
Legacy*
Samsung Internet Parses legacy; ignore for authors
Legacy*
Internet Explorer Legacy attribute era
Legacy*
language on <script> Obsolete for authors

Bottom line: *Do not ship language in new HTML. Support exists only so old pages keep working.

Key Takeaways

  • Status: deprecated / obsolete on <script> — omit in new code.
  • Replace with: plain <script> or type (modules / data blocks).
  • Not lang: page language uses the lang attribute.
  • Goal: recognize legacy markup; never introduce it in new tutorials or apps.

One line: drop language from scripts — use nothing for classic JS, or type when you need a special script kind.

Frequently Asked Questions

A legacy attribute on script that tried to name the scripting language (often language="JavaScript"). It is obsolete in modern HTML and should not be used in new pages.
No. language on script is a deprecated scripting hint. lang is a global attribute that declares the natural language of page content (for example html lang="en").
No. The HTML Standard says authors should omit it. For classic JavaScript, use a plain script tag. For modules or data blocks, use the type attribute.
With the value JavaScript it has no useful effect in conforming documents. If type is also present, language is ignored. Prefer omitting language entirely.
Omit the attribute for normal JavaScript, or use type (for example type="module", type="importmap", or a MIME type for a data block). Do not invent new language values.
So you can recognize it in old tutorials and codebases, avoid copying it into new work, and migrate safely to modern script markup.

Next: list

Learn the list attribute that links an input to a datalist.

list 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.

8 people found this page helpful