HTML attributes

      No Comments on HTML attributes

HTML attributes are used to define characteristics of a HTML element.

HTML attributes-features

  • All HTML elements can have attributes
  • Attributes provide additional information about that element
  • Html attributes are always specified in start tag
  • Attributes usually have two parts: name=”value”. 

Name refers to the name of the property you wish to set. For example, one wants to align <p> , the property alginmnet is named as align.

Value is the value assigned to the property. For example <p> aligned to right, the value will be right.

<html>
<head>
</head>
<body>
<p align="right">this is right aligned
 </p>
<p align="center">this is center aligned
 </p>
<p align="left">this is left aligned
 </p>
</body>
</HTML>

this is right aligned

this is center aligned

this is left aligned

The lang attribute

The language of document should be decalared. The language is decalred in the <html> tag. The language is declared using lang  attribute.

<html lang="en">
.
.
.
.
</html>

Th href attribute

Html links are specified in <a> tag.The link address is defined by using href attribute.

<a href="scanfcode.htm">link</a>

The title attribute

A title attribute is added to <p> tag.The value of title attribute is displayd as a tooltip on mover over on paragraph.

<p title="I am a paragraph">this is a paragraph with title attribute that will be shown as tooltip.</p>

this is a paragraph with title attribute that will be shown as tooltip.


Size attributes

The size attributes has two properties height that specifies the heigth for an element and width that js used to specifiy width of an element.

<img src="scanfocdd.png" width="120" height="200" alt="HTML attributes"/>

The alt attribute

Alt attribute is used to provide an alternate text for image, when it cannot be displayed on screen. The text in alt can be read by screen users.

<img src="scanfocdd.png" width="120" height="200" alt="HTML attributes"/>

id and class attributes

id and class attributes specify name of class and id for that element.

<p id="id1">para 1</p>
<p class="class1">para 2</p>

These can be used to apply java script or styling to elements.They can be applied to all HTML elements.

Leave a Reply

Your email address will not be published. Required fields are marked *