What is alink attribute?
In HTML, it is common practice to enclose code lines within tags, each tag conveying a specific meaning to the browser. Tags come with unique attributes that enhance the functionality of the associated component when specified within the tag. Similarly, within the body tag, which encompasses all other tags, we have the alink attribute.
The alink attribute is utilized to specify the color of an active link within a webpage. By default, active links appear in blue, but the alink attribute enables us to customize this color to our preference.
Syntax:
<body alink = colorName/hexCode/RGBValue>
</body>
colorName: We have the option to specify the desired color directly by indicating names such as 'yellow', 'blue', or 'green'.
Hexadecimal Code: In this context, we can specify the hexadecimal code for the desired color, such as #ffffff. The hex code consists of six characters from 0 to 9 and always begins with #. For instance, #ffffff corresponds to the color white, while #000000 corresponds to the color black.
RGB Color Values: It is a common knowledge that colors are composed of varying amounts of Red, Green, and Blue. To specify a color, we assign RGB values ranging from 0 to 255. For instance, 000 signifies black, while 255, 255, 255 denotes white.
Example:
<!DOCTYPE html>
<html>
<head>
<title>
HTML body alink Attribute from C# Tutorial
</title>
</head>
<body alink="yellow" link="blue">
<center>
<h1 style="color:green yellow;">
Welcome to our tutorial
</h1>
<h2>HTML <body> alink Attribute is implemented </h2>
<a href="#">
Only places for all the computer science students
</a>
</center>
</body>
</html>
Output:
Explanation:
In the code snippet provided, the alink attribute has been integrated within the body element. A webpage has been constructed utilizing the body tag, within which the alink attribute has been specified with a value of yellow. This configuration dictates that any active links within the body portion will be displayed in a yellow hue. Subsequently, an h1 tag was selected and customized to exhibit a greenYellow shade. Following this, an h2 tag was employed without any specific attribute. An anchor tag, denoted by <a>, typically utilized for hyperlink creation, was then utilized with a target attribute assigned to null. In this instance, the href attribute was set to '#' to establish the link destination.
Upon executing the code, the text color within a tag should display as yellow. However, it appears as blue by default due to the absence of support for the alink attribute in HTML5.
The alink attribute was compatible with HTML versions prior to HTML5.
Note: To change the color of an active link, we cannot use alink attribute in HTML5, but we can use the CSS styling and can change the color.
Example 2:
<!DOCTYPE html>
<html>
<head>
<title>
HTML body alink Attribute from C# Tutorial
</title>
<link rel="stylesheet" href="style.css">
</head>
<body alink="yellow" link="blue">
<center>
<h1 style="color:greenyellow;">
Welcome to our tutorial
</h1>
<h2>HTML <body> alink Attribute is implemented </h2>
<h3>This is link 1 which has some different color</h3>
<a href="#" id="link1">
Only places for all the computer science students
</a>
<h3>This is link 2 which has some different color</h3>
<a href="#" id="link2">
Only places for all the computer science students
</a>
<h3>This is link 3 which has some different color</h3>
<a href="#" id="link3">
Only places for all the computer science students
</a>
<h3>This is link 4 which has some different color</h3>
<a href="#" id="link4">
Only places for all the computer science students
</a>
</center>
</body>
</html>
CSS code:
#link1{
color:yellow;
}
#link2{
color:red;
}
#link3{
color:green;
}
#link4{
color:gray;
}
Output:
Explanation:
- In the above code, we have used two files in which one file contains the HTML code, and one file contains the CSS code. We used the external CSS method to change the color of the active link in the code.
- In the body tag, we used the four links using a tag and gave all of them different ids with some text.
- Now, in the CSS file for each id, we set the color attribute to different colors, and we are able to change the color of each link with the color attribute.
- Instead of writing color names, we can write their hex code or the RGB values according to the preferred color.