HTML attributes provide additional information about HTML elements. Most of the html elements have attributes that are always specified in the starting tag of these elements. They usually concise name and value pairs following the pattern:  name = "value". Following are some important attributes that are frequently use in HTML.

1: The href Attribute:
This attribute is use to add link of internal or external resources. The links are defined through <a> tag element and the path or address of the link is specified in the href attribute. In the following example " https://virtualcode4.blogspot.com " is the link of an external source specified in the href attribute.
Example: 
           <a href =https://virtualcode4.blogspot.com "></a>

2- The src Attribute: 
This attribute is mostly use with <img> and <script> tag to specified source or location of a file. The filename of the image source or script source is provided using src attribute.
In the given example, flower.jpg and bootstrap.min.js are the name of source files whereas 'images' and 'js' are folders in which they are placed. 
Example:
             <img src =" images/flower.jpg " />       Or
             <script src =" js/bootstrap.min.js "> </script>

3- The alt Attribute: 
The alt attribute specifies an alternative text to be display in place of an image that cannot be displayed or supported in the browser. The value of this attribute can be read by the users or screen readers. It is also useful for displaying an image that does not exist.
Example:
             <img src =" images/flower.jpg " alt =" flower " />
In this case, flower attribute will display in place of image if it is unable to load in the browser or doesn't actually exist and this will make easy for users to understand the situation.

4- The Width / Height Attributes: 
When we talk about image, width and height are the important attributes that first come in our mind. This is the basic requirement of every element to set it's width and height and for that we use CSS but in <img> tag, we can specify the dimension using width and height attributes.
Example:
              <img src =" images/flower.jpg " width =" 300 "  height =" 400 " />

5- The style Attribute: 

The style attribute is use to specify the styling of an element such as font-size, color, margin etc. It is basically the CSS that we apply to give life and colors to HTML. There are three types of styling, inline, internal and external. Here, I have mentioned inline styling which is use as an attribute.
Example: 
             <p style =" color: red; "Virtual Code </p>

6- The title Attribute: 
Title attribute is mostly use as a tooltip in <p> tag. So when we mouse over the paragraph written in <p> tag with title attribute, it display the text as a tooltip. We can also use this attribute to display the abbreviation. 
Example:
          <p title =" World Wide Web "WWW </p>  

Both single and double quotes can be use around attributes but when attribute value itself contains double quote then single quotes should be use outside.
Example:
             <p title = ' World "Wide" Web 'WWW </p>  

These methods should be follow when working with html, else the program will not run perfectly.




Share To:

Sawera A

Post A Comment:

0 comments so far,add yours