Generally, we use HTML elements in the simplest form but using HTML attributes we can control element's looks, size of content, the position of the content and can add other useful information with the element.
HTML attribute is special words which gives additional information to the HTML element. Attributes have two components name and value.
HTML attribute is only specified in starting tag only. You can add more than one attribute to an element by giving space between them.
The attribute has two properties:
- name: - name is the first part of the attribute which specifies the name of the attribute.
- value: - value is the second part of the attribute and it contains the value of the attribute.
HTML Core Attributes
There are few attributes which can be used with most of the HTML element. These attributes are:
1). style Attribute
The style attribute allows us to use inline CSS in our element. We can style the element by setting CSS rules in the style attribute.
Using style attribute we can add almost all CSS property to the element.
2). class attribute
The class attribute can be used in almost all HTML elements.
When a class is defined in any HTML element then that element contains all the property mentioned for that class.
The id attribute is used to uniquely identify any HTML element. An HTML document can't have more than 1 same id, each and every id should be unique.
4). title attribute
The title tag is used to provide additional information to the content of the element.
It shows the information provided when you take the mouse pointer over it.
Other useful attributes
In <a> tag href attribute is used to specify the address of the link.
src attribute is used to define file location in <img> tag.
- HTML attribute give additional information to the element.
- HTML attributes are only defined in starting tag.
- An element can have more than one attribute.
- All HTML element has 4 core attribute: title, style, id and class.