Applet tag in HTML | How to embed applet Tag In HTML

In this article, we will see about the applet tag and its uses. We also discuss Acronym Tag, Map, and Area Tag, and Abbr Tag We will also see how to use the applet tag in HTML and some examples for that. Let’s get started.

Introduction

Before learning about the <applet> tag first, we need to know what is an applet. So, let’s see the very basic definition of applet before we divide into the topic.

What is an applet?

In computing, an applet is any small application that performs one specific task that runs within the scope of a dedicated widget engine or a larger program, often as a plug-in.  It also means letting an app run on its own. Now you know where the name comes from!

An applet is a Java program that can be embedded into a web page. It runs inside the web browser and works on the client-side. Applets make the web site more dynamic and entertaining.

applet tag in HTML
Applet screen

Remember that applet is a way old tag and is no longer in use. We will anyhow see about applet tag and then its alternatives too.

Applet in HTML

The applet tag embeds the applet java programs into HTML. In other words, we run the java applet using HTML. Applet tag is a pug-in.

The applet tag deprecated from HTML 4. So the modern browsers do not support applet tag.

PUG-IN: Plug-ins are a computer program that extend the standard functionality of the browser.

Purpose of plug-in:

  • Run Java applets
  • Run ActiveX controls
  • Display Flash movies
  • Display maps
  • Scan for viruses
  • Verify a bank id
  1. ActiveX controls are no longer supported in any browsers.
  2. The support for Shockwave Flash has also been turned off in modern browsers.

Syntax

Below is the syntax for <applet> tag.

<applet code="URL" height="200" width="100">
   <param parameter1>   
   <param parameter2>
.............
</applet>

Specification

DisplayBlock
TagStart and End
UsageEmbed Applets
Specifications of <applet> tag

Attributes

The <applet> tag has specific attributes to itself. Let’s see the attributes now.

Specific attributes

AttributeValueDescription
codeURLIt specifies the URL of the Java applet class file.
widthpixelsIt specifies the display width of the applet panel.
heightpixelsIt specifies the display height of the applet panel.
align1. left
2. right
3. top
4.bottom
5.middle
Specifies the position of applet application relative to surrounding content
alttextDisplays alternative text in case the browser does not support Java.
archiveURLThis specifies the archived or compressed version of an applet application.
objectnameSpecifies the URL or reference to a serialized representation of an applet.
codebaseURLIt specifies the exact or relative URL of applets .class file specified in the code attributes.
hspacepixelsIt specifies the horizontal space around the applet.
vspacepixelsIt specifies the vertical space around the applet.
namename
It specifies the name for the applet
Specific Attributes

Global Attributes

The <applet> tag supports global attributes. Global attributes are nothing but the attributes which can be used throughout the program.

Event Attributes

The <applet> tag also supports event attributes. These are nothing but the events that occur on clicking, hovering, or moving, etc.

Browser Support

All browser do not support <applet> tags.

Browser that supports <applet>,

  • Firefox
  • Safari

Browser that doesn’t support <applet>,

  • Google Chrome
  • Internet Explorer
  • Opera

Examples

Example 1:

Now let’s see a basic example for the <applet> tag.

<!DOCTYPE html>
<html>
<applet code="Hello World" width=200 height=60>
</applet>
</html>

Here in this example, Hello World is a class file in Java that has applet coding. The width and height specify the pixels of the applet when it is opened in the browser.

Example 2:

Now let’s see an example with the parameter value.

Parameter: All the information present in the applet is hard-coded. This means the code is embedded in it. Now parameters make a way for passing the input from the user to the applets. This is similar to the command line arguments we perform in other programming languages.

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

<!DOCTYPE html>
<html>
<applet code="Hello World" width=200 height=60>
<param name="message" value="Hello">
</applet>
</html>

Here the applet code uses the Java file “Hello World“, which has a variable “message” and the value is “Hello”.

Note: There are still some browsers that support the <applet> tag with the help of some additional plug-ins/installations to work.

Alternatives

As <applet> is not supported in many browser, we will see some alternatives for this.

We can use <embed>,<object> tags instead. Let’s see them briefly.

Embed Tag

For embedding a document we use this tag.

Syntax:

<embed>

This tag is an empty tag. It doesn’t need a closing tag. Also, you can specify only the source of the documents.

Examples:

Say you want to insert a document. Then the code would be,

<embed src="snippet.html">
applet tag in HTML
Embedded document

Now let’s see another example for embedding a image.

<embed src="pic1.png">
Output

Object Tag

This is also similar to <embed> tag. Only difference is the syntax.

Syntax

<object attribute></object>

This is not an empty tag. It definitely needs a starting and a ending tag. Let’s see some examples.

Examples

Now let’s try to modify the above example itself.

<object data="snippet.html"></object>

This is for adding a document. Now for adding an image,

<object data="pic1.png"></object>

Tip: To embed a picture, it is better to use the <img> tag. To embed a document, it is better to use the<iframe> tag.

Video tag

What if if you want to add a video to your web page? Here you can use the <video> tag

Syntax

<video attributes>
...
</video>

Example

<video width="320" height="240" controls>
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
  View the video here. 
</video>

Output

applet tag
Video tag output

Audio tag

As the name says, it adds an audio file in HTML.

Syntax

<audio attribute>
...
</audio>

Example

<audio controls>
  <source src="horse.ogg" type="audio/ogg">
  <source src="horse.mp3" type="audio/mpeg">
  You inserted a audio file. 
</audio>

Output

Audio tag output

FAQ

How to embed applet in HTML?

Just use the syntax ….

Why applet tag is used in HTML?

If we want to embed either a document or some other kind of video, audio we can make use of applet tag.

Conclusion

In this article we discussed the <applet> tag. In addition to that we have discussed some alternatives of the <applet> tag also. Hope this helped you well. Keep practicing and happy coding!

Leave a Comment

Your email address will not be published. Required fields are marked *