HTML code Attribute
The obsolete HTML code attribute was historically used with the <applet> element to specify the compiled Java class containing the applet that a browser should load and run.
code attribute is obsolete and should not be used in modern HTML. Java applets and the <applet> element are also obsolete and are no longer supported by modern browsers.
Historical Syntax
The code attribute was placed on an <applet> element and specified the name of the compiled Java class to load:
<applet code="Example.class" width="400" height="300">
Alternative content
</applet>
The browser required a Java environment capable of loading and executing the specified applet. Other applet-related attributes could provide additional information about the location and resources required by the Java program.
Historical Elements
The code attribute was historically associated with the obsolete <applet> element.
| Element | Historical Purpose |
|---|---|
<applet> |
Specified the compiled Java class containing the applet to load and run. |
Historical Use
Java applets allowed webpages to provide interactive programs that could perform tasks beyond the capabilities of early HTML and browser scripting. Applets were used for applications such as games, animations, educational demonstrations, calculators, and other interactive content.
The code attribute told the browser which compiled Java class represented the applet. The browser then relied on a Java plug-in or other Java runtime support to download and execute the program.
Additional attributes such as codebase and archive could be used to identify locations or files associated with the applet.
Why It Became Obsolete
The code attribute became obsolete along with the <applet> element and browser support for Java applets. Applets depended on external browser plug-ins and presented compatibility, maintenance, and security concerns.
Modern browsers provide extensive native capabilities through HTML, CSS, JavaScript, graphics APIs, media elements, and other web platform technologies. These technologies allow interactive content to run without requiring a Java browser plug-in.
Modern Alternative
There is no direct modern HTML replacement for the code attribute because modern browsers do not run Java applets. Existing applet-based content must be redesigned using technologies appropriate for the application's purpose.
Modern interactive webpage functionality is commonly created with HTML, CSS, and JavaScript:
<button type="button" id="message-button">Show Message</button>
<p id="message"></p>
<script>
const button = document.getElementById("message-button");
const message = document.getElementById("message");
button.addEventListener("click", function () {
message.textContent = "Hello from JavaScript!";
});
</script>
More specialized applications may use technologies such as Canvas, SVG, WebGL, WebAssembly, HTML media elements, or other web APIs. The appropriate replacement depends on what the original Java applet was designed to do.
Because the obsolete code attribute itself has no direct modern equivalent, a live editor example would demonstrate an unrelated technology rather than a replacement for the attribute.
Legacy Browser Support
The code attribute was used by browsers that supported Java applets through a compatible Java environment or browser plug-in. Its usefulness depended on support for the obsolete <applet> element and Java browser technology.
Modern browsers no longer provide the Java plug-in environment required to run traditional Java applets. Old webpages containing <applet> and code may still expose the markup in their source, but the original applet should not be expected to run.
For additional information about historical browser compatibility, visit Can I Use? . Search for the HTML element or attribute you want to check. Search results can include related HTML features, element attributes, APIs, and other technologies, so select the result that most closely matches the legacy feature you are researching.
Related Attributes
Other obsolete HTML attributes historically associated with Java applets and embedded content include:
Specifications
The code attribute and the <applet> element are obsolete and should not be used in modern HTML. See the WHATWG HTML Living Standard for information about obsolete and non-conforming features.
