Learning HTML 3.2 by Examples, section 5 Descriptions of HTML 3.2 tags:

APPLET - Java applets (Not in HTML 2.0!)


To embed a Java applet into an HTML document.

Typical rendering

If the browser is Java enabled, it runs the applet; this typically means that some animation (perhaps an interactive one) is shown in an area within the browser window. If not, it displays the contents (after PARAM elements) of the applet, or the string specified in the ALT attribute.

Basic syntax

<APPLET CODE="appletfile" WIDTH=m HEIGHT=n> textual description </APPLET>

Possible attributes

attribute name possible values meaning notes
CODEBASE URL the base URL of the applet; this typically refers to the directory or folder containing the code of the applet default is the URL of the document
CODE string class file, i.e. the name of the file that contains the compiled Applet subclass of the applet obligatory; interpreted as relative to the base specified by the CODEBASE attribute; cannot be absolute
ALT string a textual description, to be displayed in place of applet the contents of the element can be used for the same purpose, with more flexibility
NAME string a name for the applet instance such names make it possible for applets in the same document to find (and communicate with) each other.
WIDTH integer suggested width, in pixels, not counting any windows or dialogs which the applet brings up obligatory
HEIGHT integer suggested height, in pixels, not counting any windows or dialogs which the applet brings up obligatory
ALIGN TOP, MIDDLE, BOTTOM, LEFT, RIGHT positioning of the applet display area similar to ALIGN attribute of IMG
HSPACE integer suggested horizontal gutter (width of white space to the immediate left and right of the applet display area), in pixels cf. to HSPACE attribute of IMG
VSPACE integer suggested vertical gutter (height of white space above and below the applet display area), in pixels cf. to VSPACE attribute of IMG

Allowed context

Text container, i.e. any element that may contain text elements. This includes most HTML elements.


Zero or more PARAM elements followed by zero or more text elements.

The exact meaning and intended use of text elements in the contents is somewhat obscure. The following is the wording of the HTML 3.2 Reference Specification:

Following the PARAM elements, the content of APPLET elements should be used to provide an alternative to the applet for user agents that don't support Java. - - Java-compatible browsers ignore this extra HTML code. You can use it to show a snapshot of the applet running, with text explaining what the applet does. Other possibilities for this area are a link to a page that is more useful for the Java-ignorant browser, or text that taunts the user for not having a Java-compatible browser.
Notice that text elements in the contents and ALT attribute in the start tag are two ways of having something displayed in place of the applet. There are two differences: the value of ALT is a plain string, whereas the elements may contain text markup; and an ALT attribute has no effect if the browser does not know an APPLET element at all, whereas such a browser probably processes the text elements in the contents - it simply ignores the APPLET (and PARAM) start and end tags.


A simple example: an applet which draws animated bubbles.

Example APPLET-1.html:

<APPLET CODEBASE="http://java.sun.com/applets/other/Bubbles/classes"
   CODE="Bubbles.class" WIDTH=500 HEIGHT=500 ALIGN=MIDDLE>
<P><IMG SRC="bubbles.gif" ALT="[GIF image (2k)]"><BR>
An extract from a snapshot of <CITE>Bubbles</CITE> animation
by <A HREF="http://java.sun.com/">java.sun.com</A>.</P>
A more complicated example, using parameter passing (PARAM element):
<PARAM NAME=snd VALUE="Hello.au|Welcome.au">

An example of typical (?) use of Java applets for "decorative" purposes (which many people find annoying):

<APPLET CODEBASE="applets/NervousText"
<IMG SRC="sorry.gif" ALT="This looks better with Java support">

Our final example, as well as the first one, uses Java demo code from java.sun.com. It runs an applet for a nice game. Of course, the essential thing is the applet itself. The HTML constructs needed are simple and similar to the ones above. However, here the alternative texts just inform the user about Java being not in use. In cases like this, where the applet is essential, such notes might be the best you can do, although you might consider providing a snapshot for illustration (as in the first example) to help the reader to decide whether he really wants to see the applet in action.

Example APPLET-4.html:

<H3>Multilingual Word Match Game</H3>
<P>This demonstration uses a Java applet
(from <A HREF="http://java.sun.com/">java.sun.com</A>),
so you need Java enabled on your browser to see it.</P>
<P>First select a language on the left. The match words with
pictures, clicking first on a picture, then on a word. Click
on "score" to see how well you did.</P>
  WIDTH=500 HEIGHT=350
  ALT="(Your browser recognizes the APPLET element but does
not run the applet.)">
<EM>Your browser either has no Java support at all or
it has Java support disabled.</EM>


In HTML 4.0, the APPLET element is deprecated in favor of the new OBJECT element. However, the implementation of OBJECT is broken in many popular browsers.

Java is an object-oriented programming language (somewhat similar to C++) developed by Sun. A Java applet is a Java program which is executed by an interpreter invoked by (some) Web browsers upon encountering an APPLET element. Java applets can be used for animations, games, etc.

Even if a browser supports Java, the support can be disabled by system administration or by individual users, and people often do this because they think Java has too many security risks. Therefore, if you use Java applets, try to design your documents so that they work (although perhaps unimpressively) with Java disabled, too.

There is a very large number of Java applet examples on the Web. For some collections, see FREE Java and JavaScript at TheFreeSite.com. (But make sure you understand the difference between Java and JavaScript!)

Date of last update: 2010-12-16.
This page belongs to the free information site IT and communication, section Web authoring and surfing, by Jukka "Yucca" Korpela.