Skip to main content

HTML Tags

HTML <applet> Tag

Written by Updated HTML <applet> Tag exercises

The applet tag embedded small Java programs, called applets, into web pages in the 1990s and 2000s. Browsers removed Java support years ago for security reasons, so applets no longer run anywhere. The tag is obsolete.

What it did

Syntax

html

<applet code="ClassFileName.class" width="300" height="200">
  Your browser does not support Java applets.
</applet>

Attributes

AttributeDescription
codeSpecifies the name of the Java class file to be loaded.
archiveSpecifies the location of the applet’s .jar file.
codebaseDefines the base URL for the applet’s class files.
widthSpecifies the display width of the applet.
heightSpecifies the display height of the applet.
nameAssigns a name to the applet instance.
altProvides alternate text for browsers that do not support Java applets.
objectSpecifies the serialized applet object.
alignDefines alignment relative to surrounding elements.
hspaceSets horizontal space around the applet.
vspaceSets vertical space around the applet.

None of these attributes do anything in a current browser.

Example

html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Applet Tag Example</title>
</head>
<body>

<h2>HTML &lt;applet&gt; Tag Example</h2>

<applet code="HelloWorld.class" width="300" height="200">
  Your browser does not support Java applets.
</applet>

<p><strong>Note:</strong> Modern browsers no longer support Java applets. Use the &lt;object&gt; tag instead.</p>

</body>
</html>

A current browser shows only the fallback text, or nothing at all. The applet itself never starts.

Browser Support

Chrome
Edge
Firefox
Safari
Opera
IE9+
NoNoNoNoNoPartially

What replaced applets

Nothing replaces them one to one, because Java in the browser is gone. What applets were used for is done today with:

  • JavaScript for interactive tools, games and calculators.
  • <canvas> and WebGL for drawing and animation. See the canvas tag.
  • WebAssembly for heavy computation, including code originally written in other languages.

If an old page still contains <applet>, the content has to be rebuilt with these, not wrapped in another tag.

HTML <applet> Tag exercises

Use a canvas instead

Applets are gone. Make a drawing surface for JavaScript with the id board, 300 wide and 150 high.

Result

Check your answer to see it here.