👀 Live Preview
Legacy <applet> markup (modern browsers show fallback content):
applet with codebase — Java applets are not supported in modern browsers. Fallback text appears instead.

The codebase attribute in HTML is used with the <applet> and <object> elements to specify the base URL for resources associated with an embedded application or plugin. It tells the browser where to fetch supplementary files—such as Java class files, JAR archives, or other assets—that the embedded content needs. This attribute was common in legacy pages that used Java applets and is now largely obsolete in modern web development.
Legacy use.
Also supported.
Resource root.
Doc-relative.
JS update.
Not global.
codebase AttributeThe primary purpose of the codebase attribute is to provide a base URL for the browser to locate additional resources required by an embedded application or applet. By setting codebase, developers could ensure the browser knew where to find files referenced by the code or data attributes—for example, a .class file or supporting JAR archive on a remote server.
codebase sets a base URL for resources of a specific <applet> or <object>. The <base> element sets the default base URL for links, images, and forms across the entire document.
Add codebase to an <applet> or <object> element with a URL value:
<applet code="MyApplet.class" codebase="http://example.com/applet/" width="300" height="200">
Your browser does not support Java applets.
</applet><applet> (obsolete) and <object>.code on applet or data / classid on object.<base href>.The codebase attribute accepts a URL value that specifies the base URL for embedded resources. This URL can be relative or absolute. Relative URLs are resolved relative to the URL of the document containing the codebase attribute.
Points to a full server path for applet or object resources:
<applet code="MyApplet.class" codebase="http://example.com/applet/">
Fallback content
</applet>Resolved against the current document’s location:
<object data="plugin.swf" codebase="assets/plugins/" type="application/x-shockwave-flash">
<p>Plugin not available.</p>
</object>| Aspect | Details | Modern Alternative |
|---|---|---|
| Elements | <applet>, <object> | <iframe>, <video>, JS modules |
| Value type | URL (absolute or relative) | Full URLs in src / data |
| Pairs with | code, archive, classid | Single src attribute |
| JS access | setAttribute("codebase", url) | Update src or load modules |
| Scope | Per embedded element | <base href> for whole page |
| HTML5 status | Legacy / obsolete | Avoid in new projects |
| Element | Supported? | Notes |
|---|---|---|
<applet> | Yes (obsolete) | Primary historical use; removed from HTML5 |
<object> | Yes (legacy) | Base URL for object resources alongside data |
<embed> | No | Uses src directly |
<base> | No | Different attribute: document-wide base URL |
<script src> | No | Scripts use full or relative src paths |
Applet codebase URL example and dynamic JavaScript setAttribute.
Legacy <applet> markup (modern browsers show fallback content):
applet with codebase — Java applets are not supported in modern browsers. Fallback text appears instead.
Here’s a basic example demonstrating the usage of the codebase attribute:
<applet code="MyApplet.class" width="300" height="200" codebase="http://example.com/applet/">
<!-- Additional applet parameters and content -->
Your browser does not support Java applets.
</applet>In this example, the codebase attribute is set to http://example.com/applet/, indicating that the browser should look for the MyApplet.class file and other resources in that location.
While the codebase attribute is typically static in HTML markup, you can change it dynamically with JavaScript when the base URL must be determined at runtime:
<applet id="myApplet" code="MyApplet.class" width="200" height="100">
Your browser does not support Java applets.
</applet>
<script>
var appletElement = document.getElementById("myApplet");
appletElement.setAttribute("codebase", "http://example.com/dynamic/");
</script>In this script, the codebase attribute of the applet element with id myApplet is dynamically changed to http://example.com/dynamic/ using setAttribute.
<applet> or <object> when plugins fail.Add a URL on <applet> or <object> alongside code or data.
Relative paths resolve against the document URL; absolute paths use the given server.
Class files, JAR archives, and related assets load from the base URL.
Modern browsers skip applets and show fallback content instead.
The codebase attribute for Java applets is obsolete. All major browsers have removed applet support. The attribute remains in the spec for <object> but is not used in modern web development.
Use <iframe>, <video>, ES modules, or Web APIs instead of applets.
Bottom line: Learn codebase for legacy maintenance only. Do not use applets or codebase in new web applications.
codebase to specify the base URL for embedded applet or object resources in legacy codecodebase from the document <base> elementcodebase to specify the base URL for resources associated with your application or applet, ensuring the browser can locate and load them correctly.The codebase attribute is a useful tool for specifying the base URL for resources associated with HTML applications or applets. By understanding how to use this attribute effectively, developers can maintain legacy web-based applications that relied on embedded Java content.
For new projects, prioritize secure, widely supported technologies instead of applets and plugin embeds. Understanding codebase helps when reading or updating older HTML documents.
codebaseBookmark these when reading legacy HTML.
Resource root.
PurposeLegacy tag.
ElementDoc-relative.
ValueJS update.
ScriptNot global.
Compare<applet> or <object>, such as class files or JAR archives.codebase applies to a single embedded element. <base href> sets the default base URL for the entire document’s links and forms.<applet> (obsolete) and <object>. It is not a global attribute on other elements.element.setAttribute("codebase", "http://example.com/path/") on the applet or object element.Explore the obsolete codebase attribute on <applet> and <object>, and learn why modern sites use iframe and HTML5 instead.
5 people found this page helpful