|Contents||% elements followed by block-level elements and/or inline elements|
|Contained in||Inline elements, block-level elements except pre|
The applet element is used to embed Java applets. It has been deprecated in XHTML 1.0 in favor of the more generalized object element. However, since the few browsers that support object do so with significant bugs, applet is currently a more reliable method of embedding Java applets.
applet's code attribute specifies the name of the class file that contains the compiled Applet subclass. The value is relative to the URI specified in the codebase attribute, or to the XHTML document's base URI if the codebase attribute is not given.
The required width and height attributes define the dimensions of the applet. The value may be given in pixels or as a percentage of the parent element's width or height.
The alt attribute can be used to give alternate text for browsers that recognize the applet element but do not support Java or do not have Java enabled. Authors can also give alternate content between the start and end tags of the applet element--a better method than using the alt attribute since it allows authors to include XHTML markup in the alternate content and also works with pre-HTML 3.2 browsers that do not support applet.
An applet may contain param elements to define applet-specific parameters. param elements should be specified before any other content of the applet element. In the following example, a decorative Java applet takes two parameters. The applet contains an animated GIF as an alternative for non-Java browsers.
code="animate.class" width="100" height="100">
<param name="img1" value="/images/1.jpg" />
<param name="img2" value="/images/2.jpg" />
<img src="animation.gif" alt="" width="100" height="100" />
The archive attribute can specify a comma-separated list of archived files (either absolute URIs or URIs relative to the codebase), allowing the browser to download many files with a single connection and hence decreasing the total download time. The standard archive format for Java files is JAR. JAR files can be created with the jar tool included with the Java Development Kit 1.1 and up.
Note that some browsers do not support the archive attribute, so all necessary files should be available unarchived as well. Other browsers only support a single URI as the archive value.
The object attribute specifies a serialized (saved) representation of an applet. The code attribute should not be used if and only if the object attribute is specified. When the applet is deserialized, its init() method is not invoked, but its start() method is. Sun recommends restraint in using this poorly supported feature.
The align attribute specifies the alignment of the applet. The values top, middle, and bottom specify the applet's position with respect to surrounding content on its left and right.
align="middle" aligns the center of the applet with the current baseline. To center the applet horizontally on the page, place the applet in a centered block, e.g.,
align="center"><applet code="game.class" width="300"
The other align values, left and right, specify a floating applet; the applet is placed at the left or right margin and content flows around it. To place content below the applet, use <br clear="left"|"right"|"all"> or the CSS clear property on the next element as appropriate.
The vertical-align and float properties of Cascading Style Sheets provide more flexible methods of aligning applets.
The hspace and vspace attributes allow an author to suggest horizontal gutters and vertical gutters, respectively, around the applet. The value must be in pixels and applies to both sides of the applet. Style sheets provide more flexibility in specifying the space around applets.