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.
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.
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
- ActiveX controls are no longer supported in any browsers.
- The support for Shockwave Flash has also been turned off in modern browsers.
Below is the syntax for <applet> tag.
<applet code="URL" height="200" width="100"> <param parameter1> <param parameter2> ............. </applet>
|Tag||Start and End|
The <applet> tag has specific attributes to itself. Let’s see the attributes now.
|code||URL||It specifies the URL of the Java applet class file.|
|width||pixels||It specifies the display width of the applet panel.|
|height||pixels||It specifies the display height of the applet panel.|
|Specifies the position of applet application relative to surrounding content|
|alt||text||Displays alternative text in case the browser does not support Java.|
|archive||URL||This specifies the archived or compressed version of an applet application.|
|object||name||Specifies the URL or reference to a serialized representation of an applet.|
|codebase||URL||It specifies the exact or relative URL of applets .class file specified in the code attributes.|
|hspace||pixels||It specifies the horizontal space around the applet.|
|vspace||pixels||It specifies the vertical space around the applet.|
It specifies the name for the applet
The <applet> tag supports global attributes. Global attributes are nothing but the attributes which can be used throughout the program.
The <applet> tag also supports event attributes. These are nothing but the events that occur on clicking, hovering, or moving, etc.
All browser do not support <applet> tags.
Browser that supports <applet>,
Browser that doesn’t support <applet>,
- Google Chrome
- Internet Explorer
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.
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.
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.
For embedding a document we use this tag.
This tag is an empty tag. It doesn’t need a closing tag. Also, you can specify only the source of the documents.
Say you want to insert a document. Then the code would be,
Now let’s see another example for embedding a image.
This is also similar to <embed> tag. Only difference is the syntax.
This is not an empty tag. It definitely needs a starting and a ending tag. Let’s see some examples.
Now let’s try to modify the above example itself.
This is for adding a document. Now for adding an image,
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.
What if if you want to add a video to your web page? Here you can use the <video> tag
<video attributes> ... </video>
<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>
As the name says, it adds an audio file in HTML.
<audio attribute> ... </audio>
<audio controls> <source src="horse.ogg" type="audio/ogg"> <source src="horse.mp3" type="audio/mpeg"> You inserted a audio file. </audio>
Just use the syntax ….
If we want to embed either a document or some other kind of video, audio we can make use of applet tag.
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!