HTML Attributes
An HTML attribute is a piece of markup language used to adjust the behavior or display of an HTML element. For example, attributes can be used to change the color, size, or functionality of HTML elements.
Attributes are used by including them in an opening HTML tag:
HTML Core Attributes
- id
- title
- class
- style
The Id Attributes
The id attribute of an HTML tag can be used to uniquely identify any element within an HTML page. There are two primary reasons that you might want to use an id attribute on an element:
- 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. They syntax for the title attribute is similar as explained for id attribute:
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.
The Style Attribute
The style attribute allows you to specify Cascading Style Sheet (CSS) rules within the element.
The href Attribute
The
The src Attribute
The <img> tag is used to embed an image in an HTML page. The src attribute specifies the path to the image to be displayed:
The width and height Attributes
The <img> tag should also contain the width and height attributes, which specify the width and height of the image (in pixels):