HTML Attributes

HTML Attributes:

HTML attributes are a additional information about the HTML element. It is a name value pairs like name="value". Attributes is always place inside start tag of the HTML element.

HTML Attributes has been put inside start tag of an HTML element.Do not place HTML attribute inside closing tag of any HTML element.

The href Attribute

The <a> tag has a href attribute that contains the URL of the connected web page.


Example

Source Code

Try it now

Note: The HTML hyperlink element has href and title attribute. The href attribute of the HTML element is used to link the path of another web page while the title describes the web page.

The src Attribute Of An Image

The <img> tag us basically used to show the images.It has src attribute that specifies the path URL of the displaying image.


Example

Source Code

Try it now

Note:The HTML element <img> has an src attribute that is used for providing a path of the image.

Image Attribute:Width & Height

The is also consists of width and height attributes that specify the width and height of the image respectively.


Example

Source Code

Try it now

Note: The HTML element has a width and height attribute that is used to provide the width and height of the image.

The alt Attribute Of Image

The <img> has attribute alt that is very useful during any path error of the image because it displays alt message when the image does not display on the screen due to server error.


Example

Source Code

Try it now

Note:The HTML <img> element has an alt attribute that is used to provide additional information about the image and it displays on the screen whenever the image file path is not loaded by the browser.

Style Attribute

The style attribute is used to add styles to an HTML element,such as font,size,color ,etc.

Example

Source Code

Try it now

Note:The HTML element <style> is used for writing inline CSS rule.

The id Attribute

The id attribute provides unique identification of the HTML element hence it is very easy to select this element using CSS or JavaScript.

Source Code

Try it now

Note:The id attribute of an HTML element is unique and the CSS rule regarding the id attribute is only applicable to a single element of an HTML document.

Class Attributes

The class attribute is also used to identify the element but it is not unique since one class value can be assigned to other elements too.

Source Code

Try it now

Note: The class attribute of an HTML element is used for providing CSS rules to more than one HTML element.

Online Test / Quiz