HTML Attributes
HTML Attributes supply additional information to the HTML tag. Many times it is used to enhance the capability, look and feel of the HTML Elements.
HTML Attributes Definition
It is also considered as parameter of HTML tag. The attribute in HTML is used to provide value to some setting required to the HTML tag.
- It is used to modify the look and feel to the HTML Elements.
- It is used to supply the parameter value to the HTML Elements.
- It is always specified in the start tag.
HTML Tags and Attributes
Some of the HTML tags uses it to specify the additional information, like <a> tag and <img> tag.
- href is the Attribute in the link tag (<a> tag).
- src is the Attribute to the img tag (<img> tag).
Example 1 – <a> tag used to link other HTML web page. And in the link tag you have to specify the target HTML web page address. The below syntax is used to provide the target address in the link tag.
<a href="https://www.elextutorial.com"> This is a link </a>
Using the href attribute we will specify the address of target web page. When user click on this link text the browser will load new web page specified in the href attribute.
Note: Syntax to specify the attribute and its value.
<TAGNAME Attribute_Name="Attribute_Value">Content</TAGNAME>
Example 2 – If you want to specified the source of image than src attribute is used. And <img> element is used to embed the image in the HTML wen page.
<img src="flower.jpg">
The src attribute value is the File name with its directory.
Caution: If image file exist in the same directory than no need to specify the directory.
Warning: Make sure the file name spell correctly with its file extension. Or in other words file name, location of the file and the extension of the file must be correct.
Complete Code For the image element with attribute is as below.
<html> <body> <img src="flower.jpg"> </body> </html>
Example 3 – If you want to specified the size of HTML image than the width and height Attribute are used.
<img src="flower.jpg" width="100" height="500">
Using Height and Width Attribute, the Height and Width of the image is set. And Above syntax shows that how you can set image display