HTML Attributes

HTML Attributes are part of the HTML Tags & elements. These attributes specify some additional style or special information about the HTML tags.

Most of the time attributes are specified as pairs. For example: attribute="value"

Syntax of HTML Attributes

Attributes are always specified within a start tag. First, we need to specify the name of the attribute and then, we assign a value to it (name=”value”)

Example: <h1 title="My Title"> My Heading </h1> tag.


The title Attribute

Each HTML Tag allows some specific attributes. Some HTML Attributes are used by many different elements. For example, Title attribute can be used in almost every HTML element.

HTML Title attribute is used to display some titles to users when they mouse over that element. For example: Example: <h1 title="My Title"> My Heading </h1> tag.

In above example, when user will take his mouse to "My Heading" text a Title (like tooltip) "My Title" will be visible to user.


The lang Attribute

HTML lang attribute is used to declare the language of html page content. This attribute is very helpful for screen readers and search engines.

Example: <html lang="en-US"></h1> tag.


The align Attributes

HTML align attribute can be used in paragraphs, images and few other tags for horizontal alignment. This align attribute can have 3 main values (left, right and centre). By using those values you can align a paragraph content into left, right or centre in the browser window.

<p align="left">This content is left aligned</p>
<p align="center">This content is aligned center</p>
<p align="right">This text is right aligned</p>

HTML width & height Attributes

You can set HTML images height & width using these HTML attributes. Images are defined using HTML images are defined with the

tag. There is another attribute called “src” in this tag. It is used to specify the path of the image.

Example: <img src="tutorialsclass-logo.jpg" width="200" height="300">


The style Attribute

HTML style attribute is one of the most used attributes to specify the style rules for different HTML elements. Using style attribute, we can set border, color, font size, background color, and many other styles.

Example: <p style="color:red;"> This is Tutorials Class</p>


HTML Example with various Attributes

<!DOCTYPE html>
<html>
<body>
 
<h1 title="My Title"> My Heading </h1>
<p align="center">This content is aligned center</p>
<p style="color:red;"> This is Tutorials Class's red content</p>
<img src="tutorialsclass.jpg" width="300" height="200" alt="Alternate Text" title="Tutorials" />
<a href="http://tutorialsclass.com"> Go to Tutorials Class Website </a>
 
</body>
</html>

You can read about more HTML attributes for various HTML Elements in each chapter. For example, anchor tag use "href" attribute for links. Image tag use "alt" attribute for alternate text.


Congratulations! Chapter Finished. Learn more about the similar topics:
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.