Html Attributes

We have seen few HTML tags and their usage like heading tags <h1>, <h2>, paragraph tag <p> and other tags. We used them so far in their simplest form, but most of the HTML tags can also have attributes, which are extra bits of information.

Example :-

Result :-
Align Attribute Example

This is left aligned

This is center aligned

This is right aligned

Core Attributes

The four core attributes that can be used on the majority of HTML elements

The Id Attributes

The id attribute of an HTML tag can be used to uniquely identify any element within an HTML page.

  • If an element carries an id attribute as a unique identifier, it is possible to identify just that element and its content.
  • 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.
  • The Title Attributes

    The title attribute gives a suggested title for the element

    The behavior of this attribute will depend upon the element that carries it, although it is often displayed as a tooltip when cursor comes over the element or while the element is loading.

    Example :-

    Result :-
    The title Attribute Example

    Titled Heading Tag Example

    The Class Attributes

    The class attribute is used to associate 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.

    Example :-

    The Style Attributes

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

    Example :-

    Result :-
    The style Attribute

    the style attributes...