Open In App

HTML applet Tag

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

The <applet> tag in HTML was used to embed Java applets into any HTML document. The <applet> tag was deprecated in HTML 4.01, and its support has been completely discontinued starting from HTML 5. Alternatives available in HTML 5 are the <embed> and the <object> tags. Some browsers still support the <applet> tag with the help of some additional plug-ins/installations to work.

The <applet> tag takes a number of attributes, with one of the most important being the code attribute. This code attribute links a Java applet to the concerned HTML document. It specifies the file name of the Java applet.

Note: The <applet> tag supports all Event Attributes and Global Attributes in HTML. The Applet Tag is not supported in HTML5.

Syntax:  

<applet attribute1 attribute2....>
<param parameter1>
<param parameter2>
....
</applet>

Attributes:

Attribute Values Description
align Specifies the alignment of an applet.
alt Specifies an alternate text for an applet.
archive Specifies the location of an archive file.
border Specifies the border around the applet panel.
codebase Specifies a relative base URL for applets specified in the code attribute.
height Specifies the height of an applet.
hspace Defines the horizontal spacing around an applet.
mayscript Indicates whether the Java applet is allowed to access the scripting objects of the web page.
name Defines the name for an applet (to use in scripts).
vspace Defines the vertical spacing around an applet.
width Specifies the width of an applet.

Example 1: In this example, HelloWorld is the class file, which contains the applet. The width and height attributes determine the width and height of the applet in pixels when it is opened in the browser. Attributes available to be used in conjunction with the <applet> tag are as follows:

HTML




<!DOCTYPE html>
<html>
<!-- applet code starts here -->
    <applet code="HelloWorld">
<!-- applet code ends here -->
    </applet>
</html>                                  


Parameters:

Parameters are quite similar to command-line arguments in the sense that they provide a way to pass information to the applet after it has started. All the information available to the applet before it starts is said to be hard-coded i.e. embedded within it. Parameters make it possible to generate and use data during run-time of the applet.

Syntax: 

<param name=parameter_name value=parameter_value>

The name assigned to the name attribute of the param tag is used by the applet code as a variable to access the parameter value specified in the value attribute. In this way, the applet is able to interact with the HTML page where it is embedded, and can work on values provided to it by the page during run-time.

Example 2: In this piece of code, the applet file HelloWorld can use the variable named message to access the value stored in it, which is “HelloWorld”.

HTML




<!DOCTYPE html>
<html>
<!-- applet code starts here -->
<applet code="HelloWorld">
    <param name="message" value="HelloWorld">
<!-- applet code ends here -->
</applet>
 
</html>




Last Updated : 30 Jan, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads