×

Html & Html5

The World's best Software Development Study Portal

HTML Attribute


  • All HTML elements can have attributes.
  • Attributes provide additional information about an element.
  • Attributes are always specified in the start tag.

Following are Examples of attribute:-


1. href attribute: href Attribute specified link address.
    Example:

<p> <b> HTML anchor tag </b> </p>

<p> <a href="best-html-training-institute.html">Visit our HTML tutorial </a> </p>

Output:


HTML anchor tag

Visit our HTML tutorial


2. src attribute: src attribute is used with image tag to provide the path for image to be displayed. It is used as below:
    Example:

<h2> HTML Image Example </h2>

<img src="image/himalayas.jpg" alt="himalayas" width="700" height="300">

Output:


HTML Image Example

himalayas


3. alt attribute: It is used to show alternate text if image is not displayed.The value of alt    attribute should describe the image.It is used as below:
  Example:

<h2> HTML Image Example </h2>

<img src="image/himalayas.jpg" alt="Himalayas"/>

Output:


HTML Image Example

Himalayas

4. width and height attribute: Width attribute is used to set the width of an image.Height    attribute used to set the height of an image.It is used as below:
Example:

<h2> HTML Image Example </h2>

<img src="image/himalayas.jpg" alt="himalayas" width="800" height="400">

Output:


HTML Image Example

himalayas



5. HTML style attribute: With style attribute,we can provide style to our HTML element.
  The HTML style attribute has the following syntax:


Syntax :   <tagname style="property:value;">


Example:

<h1 style="background-color:DodgerBlue;"> Hello World </h1>

Output:


Hello World