HTML Attributes square measure special words used within the gap tag to manage the element’s behavior. hypertext markup language attributes square measure a modifier of Associate in Nursing hypertext markup language part kind. Associate in Nursing attribute either modifies the default practicality of {a part|a component|part|a part} kind or provides practicality to sure element varieties unable to operate properly while not them. In hypertext markup language syntax, the Associate in the Nursing attribute is superimposed to Associate in Nursing hypertext markup language begin tag.
Several basic attributes varieties are recognized, together with
- needed attributes, required by a specific part kind for that part kind to operate correctly.
- nonobligatory attributes, wont to modify the default practicality of part type.
- customary attributes, supported by several part types.
- event attributes, wont to cause part varieties to specify scripts to be run below specific circumstances.
Some attribute varieties operate otherwise once wont to modify totally different part varieties. as an example, the attribute name is employed by many part varieties however has slightly totally different functions in every.
Table of Contents
HTML Common Attributes
Usually, hypertext mark-up language parts will take any of many commonest customary attributes (See the entire list):
Id Attributes
The id attribute provides a document-wide distinctive symbol for the part. this could be used as a CSS selector to produce display properties, by browsers to focus attention on the particular component, or by scripts to change the contents or presentation of the part. Appended to the computer address of the page, the computer address directly targets the particular component inside the document, generally a sub-section of the page. as an example,
the ID “Attributes” in ttp://www.myprograming.com/HTML#Attributes (to confer with the section “Attributes” within the “HTML” page).
Example:-
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML id Attribute</title>
</head>
<style type="text/css">
#class1{
font-size: 50px;
font-weight: 700;
color: blue;
}
#class2{
font-size: 25px;
font-weight: 600;
color: #000;
}
</style>
<body>
<h1 id="class1">Myprograming.com</h1>
<p id="class2">this is id attribute example</p>
</body>
</html>
Output:-
Myprograming.com
this is id attribute example
Class Attributes
The class attribute provides some way of classifying similar parts. this could be used for linguistics functions, or for presentation functions. Semantically, as an example, categories are employed in microformats. Presentational, as an example, AN hypertext mark-up language document may use the designation category=” notation” to point that everyone part with this class price is subordinate to the most text of the document. Such parts may well be gathered along and conferred as footnotes on a page rather than showing within the place wherever they occur within the hypertext mark-up language supply. Another presentation use would be as a CSS selector.
Example:-
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML class Attribute</title>
</head>
<style type="text/css">
.class1{
font-size: 50px;
font-weight: 700;
color: blue;
}
.class2{
font-size: 25px;
font-weight: 600;
color: #000;
}
</style>
<body>
<h1 class="class1">Myprograming.com</h1>
<p class="class2">this is style attribute example</p>
</body>
</html>
Output:-
Myprograming.com
this is style attribute example
Style Attributes
An author could use the style non-attribute codes to display properties to a specific component. The style attribute is often used on any hypertext mark-up language component (it can validate on any hypertext mark-up language component element; but, it’s not essentially useful). it’s thought-about higher follow to use AN component’s id or category attributes to pick out the element with a stylesheet, though’ typically this could be too cumbersome for an easy and specific or unexpected application of titled properties.
Example:-
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML style Attribute</title>
</head>
<body>
<h1 style="color: #606060;font-weight: 700;">Myprograming.com</h1>
<p>this is style attribute example</p>
</body>
</html>
Output:-
Myprograming.com
this is style attribute example
Title Attributes
The title attribute is employed to connect subtextual rationalization to part. In most browsers, this attribute is displayed as what’s typically noted as a tooltip.
Example:-
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML title Attribute</title>
</head>
<body>
<p title="this is title">Myprograming.com<p>
<p title="this is paragraph">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</a>
<p><strong>Note:</strong> Place mouse pointer over the text see how it works.</p>
</body>
</html>
Output:-
Note:- Place mouse pointer over the text see how it works.
Align Attributes
We have seen few HTML tags and their usage like heading tags <h1>,<h2> paragraph tag<p>and alternative tags. we have a tendency to use them to this point in their simplest kind, however, most of the HTML tags may have attributes, that area unit additional bits of knowledge.
An attribute is employed to outline the characteristics of the Associate in Nursing HTML part and is placed within the element’s gap tag. All attributes area unit created of 2 elements a reputation and a worth
The name is that the property you wish to line. as an example, the paragraph
- part within the example carries Associate in Nursing attribute whose name is aligned, that you’ll be able to use to point the alignment of paragraph <p> on the page.
- The value is what you wish the worth of the property to be set and perpetually place inside quotations. The below example shows 3 doable values of aligning attributes: left, center and right.
Attribute names and attribute values area unit are case-insensitive. However, the globe Wide internet pool (W3C) recommends minuscular attributes/attribute values in their HTML four recommendation.
Example:-
<!DOCTYPE html>
<html>
<head>
<title>Align Attribute</title>
</head>
<body>
<p align = "left">This is left aligned</p>
<p align = "center">This is center aligned</p>
<p align = "right">This is right aligned</p>
</body>
</html>
Output:-
This is left aligned
This is center aligned
This is right aligned
Internationalization Attributes
There square measure 3 internationalization attributes, that square measure offered for many (although not all) XHTML parts.
- Internationalization Attributes
- dir
- lang
- xml:lang
Dir Attribute
The dir attribute permits you to point to the browser regarding the direction within which the text ought to flow. The dir attribute will take one in every of 2 values, as you’ll be able to see within the table that follows −
ltr | left to right |
rtl | right to left |
Example:-
<!DOCTYPE html>
<html>
<html dir = "rtl">
<head>
<title>The dir Attribute Example</title>
</head>
<body>
<h3>This is how IE 5 renders right-to-left directed text.</h3>
</body>
</html>
Output:-
When dir attribute is employed among the tag, it determines, however, text is bestowed among the complete document. once used among another tag, it controls the text’s direction for simply the content of that tag.
–
lang Attribute
The lang attribute permits you to point the most language utilized in a document, however, this attribute was unbroken in markup language just for backward compatibility with earlier versions of markup language. This attribute has been replaced by the XML: lang attribute in new XHTML documents.
The values of the lang attribute area unit ISO-639 normal two-character language codes. Check markup language Language Codes: ISO 639 for a whole list of language codes.
Example:-
<!DOCTYPE html>
<html lang = "en">
<head>
<title>English Language Page</title>
</head>
<body>
<p >Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</body>
</html>
Output:-
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
xml:lang Attribute
The xml:lang attribute is that the XHTML replacement for the lang attribute. the worth of the xml:lang attribute ought to be associate degree ISO-639 country code as mentioned in the previous section.
Generic Attributes
Here’s a table of another attributes that square measure promptly usable with several of the HTML tags.
We will see connected examples as we’ll proceed to review alternative HTML tags. For a whole list of HTML Tags and connected attributes please check the relevancy HTML Tags List.