HTML codebase Attribute

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 2 Examples
Legacy & Embed

Introduction

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.

What You’ll Learn

01

applet

Legacy use.

02

object

Also supported.

03

Base URL

Resource root.

04

Relative URL

Doc-relative.

05

setAttribute

JS update.

06

vs base

Not global.

Purpose of codebase Attribute

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

💡
Not the same as <base href>

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.

📝 Syntax

Add codebase to an <applet> or <object> element with a URL value:

codebase.html
<applet code="MyApplet.class" codebase="http://example.com/applet/" width="300" height="200">
  Your browser does not support Java applets.
</applet>

Syntax Rules

  • Used on <applet> (obsolete) and <object>.
  • Value is a URL—absolute or relative to the document URL.
  • Works with code on applet or data / classid on object.
  • Always include fallback content inside the element.
  • Do not use for general page links; that is the job of <base href>.

💎 Values

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.

Absolute URL

Points to a full server path for applet or object resources:

codebase-absolute.html
<applet code="MyApplet.class" codebase="http://example.com/applet/">
  Fallback content
</applet>

Relative URL

Resolved against the current document’s location:

codebase-relative.html
<object data="plugin.swf" codebase="assets/plugins/" type="application/x-shockwave-flash">
  <p>Plugin not available.</p>
</object>

⚡ Quick Reference

AspectDetailsModern Alternative
Elements<applet>, <object><iframe>, <video>, JS modules
Value typeURL (absolute or relative)Full URLs in src / data
Pairs withcode, archive, classidSingle src attribute
JS accesssetAttribute("codebase", url)Update src or load modules
ScopePer embedded element<base href> for whole page
HTML5 statusLegacy / obsoleteAvoid in new projects

Applicable Elements

ElementSupported?Notes
<applet>Yes (obsolete)Primary historical use; removed from HTML5
<object>Yes (legacy)Base URL for object resources alongside data
<embed>NoUses src directly
<base>NoDifferent attribute: document-wide base URL
<script src>NoScripts use full or relative src paths

Examples Gallery

Applet codebase URL example and dynamic JavaScript setAttribute.

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

Implementation Example

Here’s a basic example demonstrating the usage of the codebase attribute:

index.html
<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>
Try It Yourself

How It Works

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.

Dynamic Values with JavaScript

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:

index.html
<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>

How It Works

In this script, the codebase attribute of the applet element with id myApplet is dynamically changed to http://example.com/dynamic/ using setAttribute.

♿ Accessibility

  • Provide fallback content — Always include accessible text inside <applet> or <object> when plugins fail.
  • Avoid plugin-only features — Do not rely on applets or plugins for essential functionality.
  • Use native HTML — Video, audio, canvas, and standard forms are more accessible than legacy embeds.
  • Clear messaging — Tell users when embedded content is unavailable and offer an alternative.
  • Keyboard access — Plugin content often lacked proper keyboard and screen reader support.

🧠 How codebase Works

1

Author sets codebase

Add a URL on <applet> or <object> alongside code or data.

Markup
2

Browser resolves URL

Relative paths resolve against the document URL; absolute paths use the given server.

Resolve
3

Resources are fetched

Class files, JAR archives, and related assets load from the base URL.

Fetch
=

Embedded app (legacy)

Modern browsers skip applets and show fallback content instead.

Browser Support

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.

⚠️ Legacy · Obsolete

Not for new projects

Use <iframe>, <video>, ES modules, or Web APIs instead of applets.

Legacy Applet era only
Google Chrome Applet removed
Obsolete
Mozilla Firefox Applet removed
Obsolete
Apple Safari Applet removed
Obsolete
Microsoft Edge Applet removed
Obsolete
codebase applets Obsolete

Bottom line: Learn codebase for legacy maintenance only. Do not use applets or codebase in new web applications.

💡 Best Practices

✅ Do

  • Use codebase to specify the base URL for embedded applet or object resources in legacy code
  • Ensure the specified URL is accessible and contains required files
  • Include fallback content inside the element
  • Distinguish codebase from the document <base> element
  • Test across environments when maintaining legacy intranet apps

❌ Don’t

  • Use applets or codebase in new public websites
  • Confuse codebase with document-wide base URL settings
  • Assume relative paths work without testing resolution
  • Rely on plugins for essential functionality
  • Skip fallback content when the embed fails
  • Resource location: Use codebase to specify the base URL for resources associated with your application or applet, ensuring the browser can locate and load them correctly.
  • Accessibility of files: Ensure the specified URL is accessible and contains the necessary files and resources required by your application or applet.
  • Browser compatibility: Test your application or applet across different browsers when maintaining legacy systems, as plugin support varied historically.

Conclusion

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.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about codebase

Bookmark these when reading legacy HTML.

5
Core concepts
02

applet

Legacy tag.

Element
🔗 03

Relative URL

Doc-relative.

Value
⚙️ 04

setAttribute

JS update.

Script
⚠️ 05

vs base

Not global.

Compare

❓ Frequently Asked Questions

It specifies the base URL where the browser should look for supplementary files required by an embedded <applet> or <object>, such as class files or JAR archives.
No. 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.
Yes. Relative URLs resolve against the document URL. Absolute URLs are also valid.
No for new projects. Java applets are removed from HTML5. Use iframe, video, ES modules, or Web APIs instead.
Use element.setAttribute("codebase", "http://example.com/path/") on the applet or object element.

Understand legacy embedded resources

Explore the obsolete codebase attribute on <applet> and <object>, and learn why modern sites use iframe and HTML5 instead.

Try applet example →

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.

5 people found this page helpful