6.HTML Attributes
6.HTML Attributes
HTML Attribute
HTML attributes are special words which provide additional information about the elements or attributes are the modifier of the
HTML element.
Each element or tag can have attributes, which defines the behaviour of that element.
Attributes should always be applied with start tag.
The Attribute should always be applied with its name and value pair.
The Attributes name and values are case sensitive, and it is recommended by W3C that it should be written in Lowercase only.
You can add multiple attributes in one HTML element, but need to give space between two attributes.
Syntax
1. <element attribute_name="value">content</element>
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. </head>
5. <body>
6. <h1> This is Style attribute</h1>
7. <p style="height: 50px; color: blue">It will add style property in element</p>
8. <p style="color: red">It will change the color of content</p>
9. </body>
10. </html>
Output:
1. <p style="height: 50px; color: blue">It will add style property in element</p>
Test it Now
In the above statement, we have used paragraph tags in which we have applied style attribute. This attribute is used for applying CSS
property on any HTML element. It provides height to paragraph element of 50px and turns it colour to blue.
1. <p style="color: red">It will change the color of content</p>
In the above statement we have again used style attribute in paragraph tag, which turns its colour red.
Note: There are some commonly used attributes are given below, and the complete list and explanation of all attributes are
given in HTML attributes List.
Example
With <h1> tag:
1. <h1 title="This is heading tag">Example of title attribute</h1>
1/3
Test it Now
With <p> tag:
1. <p title="This is paragraph tag">Move the cursor over the heading and paragraph, and you will see a description as a tooltip</p>
Test it Now
Code:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. </head>
5. <body>
6. <h1 title="This is heading tag">Example of title attribute</h1>
7. <p title="This is paragraph tag">Move the cursor over the heading and paragraph, and you will see a description as a tooltip</p>
8. </body>
9. </html>
Output:
Example
With link address:
1. <a href="https://www.javatpoint.com/html-anchor">This is a link</a>
Test it Now
Without link address:
1. <a href="">This is a link</a>
Example
1. <img src="whitepeacock.jpg" height="400" width="600">
2/3
Test it Now
Note: The above example also have height and width attribute, which define the height and width of image on web page.
Output:
1. <a href="https://www.javatpoint.com">A link to HTML.</a>
2. <a href='https://www.javatpoint.com'>A link to HTML.</a>
Test it Now
IN HTML5, you can also omit use of quotes around attribute values.
3/3