Home » HTML

HTML Attributes

In this tutorial, we are going to learn about the HTML attributes with detailed explanation of some of the attributes with examples.
Submitted by Jhanvi Tripathi, on July 22, 2019

Attributes are used to provide additional information of a tag such as it’s alignments, color, size of the text and other. 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 equals 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.


    <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".

Some commonly used 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.


    <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.


    <img src="yourimage.jpg" alt=" AN IMAGE ">

The other tags where the alt attribute could be used are INPUT and AREA tags.

Comments and Discussions!

Load comments ↻

Copyright © 2024 www.includehelp.com. All rights reserved.