Home »
HTML
HTML Attributes
By IncludeHelp Last updated : October 13, 2024
HTML Attributes
Attributes are used to provide additional information about a tag, such as its alignments, color, size of the text, and others. The attributes are given with the tag that is between the angular brackets after the tag name. The attributes have a name and a value. The attribute value is given after the name of the attribute with an equal to the symbol. The attributes are specified with the starting tag of the element. The value of the attribute is generally given within the double-quotes. The value could also be specified in single quotations.
Example
<FONT SIZE="10"> A TEXT </FONT>
In the above example, the FONT is the element tag and the SIZE is the attribute for the tag FONT. The attribute SIZE specifies the property of the font which is visible for the content of the font tag "A TEXT". The size has been assigned a value of "10".
Commonly Used HTML Attributes
1. The HEIGHT and WIDTH Attribute
The height and width attribute specifies these properties of the element for which it has been used, and they receive the values in pixels. An example to illustrate the height attribute is as follows:
<img src="yourimage.jpg" height="42">
The above code would generate an image with a height of 10px despite its actual height.
An example to illustrate the width attribute is as follows:
<img src="yourimage.jpg" width="42">
2. The HREF Attribute
The href attribute, it specifies the tag the URL of a page where the link has to, also the href attribute is also used to specifies the base URL for all the other related URLs for that page.
<a href="https://www.yourlink.com">Visit me</a>
The href attribute could also be applied to the anchor (a), AREA, BASE and many other tags.
3. The SRC Attribute
The src attribute specifies the location or the URL of the required file which is present at some external source. The file that is specified could be any file such as an image or an audio or any other media file. Below example illustrate the use of src to specify the image address.
<img src="yourlocationthenimagename.jpg">
Another example of the src attribute is when it used to specify a file for the script element.
<script src="myscripts.js"></script>
4. The STYLE Attribute
The style attribute is used to specify the style for HTML, that is the presentation of the content on the webpage. It gives the inline style to the element. The style attribute could be used for most of the elements as it affects the display of that element.
Example:
<p style="color:green">This is a paragraph.</p>
5. The ALT Attribute
The alt attribute is used to specify a piece of alternative information to the element. This alternative information could be for an image if in case the image is not displayed to the user.
Example:
<img src="yourimage.jpg" alt=" AN IMAGE ">
The other tags where the alt attribute could be used are INPUT and AREA tags.