4. HTML Attributes


4. HTML Attributes

So far we have used HTML tags in the simplest forms,but for most of the HTML tags we use HTML Attributes, which provides the extra information.

An attributes are used to define the characteristics of an HTML element and is placed inside the starting tag. All attributes are consists of two parts

1. Name

2. Value

Attributes are defined in name/value pairs like: name=”value”

  • The name is the property you want to set. For example, the paragraph <p>element in the example carries an attribute whose name is align, which you can use to indicate the alignment of paragraph on the page.
  • The value is what you want the value of the property to be set and always put within quotations. The below example shows three possible values of align attribute: left, center and right.



Above Example Result:



Core  HTML Attributes:

  1. Id
  2. Title
  3. Class
  4. Style

The Id Attribute:

The Id attributes is used to identify the HTML Element with in the HTML page.There are two ways to use the attributes on an element.

  1. If an element carries an id attribute as a unique identifier, it is possible to identify just that element and its content.
  2. If you have two elements of the same name within a Web page (or style sheet), you can use the id attribute to distinguish between elements that have the same name.


<p id=”html”>This para explains what is HTML</p>
<p id=”css”>This para explains what is Cascading Style Sheet</p>

The title Attribute:

The title attribute is used to give any title for the element. They syntax for the title attribute is similar as explained for id attribute: The behavior of this attribute will depend upon the element that indicated, although it is often displayed as a tooltip when cursor hovers.


HTML attributes EXAMPLE 4


Titled Heading Tag Example

Now try to bring your cursor over “Titled Heading Tag Example” and you will see that
whatever title you used in your code is coming out as a tooltip of the cursor.

The class Attribute:

The class attribute is used to link an element with a style sheet, and specifies the class of element. You will learn more about the use of the class attribute when you will learn Cascading Style Sheet (CSS). So for now you can avoid it.

class=”className1 className2 className3″

The style Attribute:

The style attribute allows you to specify Cascading Style Sheet (CSS) rules within the element.


Html Attributes example 5


Some text…



How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

Check Also

How to Create and Set Up Google Analytics Account

4.2 (5)   How to Create and Set Up Google Analytics Account Google Analytics is …