HTML Attributes
From w3cyberlearnings
Contents |
HTML - Attribute
Attribute provides additional control over the HTML elements.
HTML - Syntax Attribute
<a href="http://w3cyberlearnings.com">Learning HTML</a> <p class="check3">This is my paragraph</p> <i class="check3">This is something else.</i> <div id="mainPid">This is another used ID</div> <table border="1">...</table>
Note
- All HTML elements can have one or many attributes.
- Attribute provides additional control over the HTML element.
- Attributes are always placed in the start tag.
- Attributes contains a pair of name and value- i.e: class="goog", or href="w3cyberlearning.com"
- Attributes name and value are all lowercase letter (You may want to use upper case letter for the value).
Example - Attributes
Start Tag and Attributes | Attribute Name | Attribute Value | End Tag |
---|---|---|---|
<p class="myp"> | class | myp | </p> |
<pre id="yop"> | id | yop | </pre> |
<a href="w3cyberlearnings.com"> | href | w3cyberlearnings.com | </a> |
<table border="1" cellspacing="1"> | border,cellspacing | 1, 1 | </table> |
Example 1: Set the <p> for a blue background
- attribute name=style
- attribute value=background-color:blue
<p style="background-color:blue">This is a blue background</p>
Example 2
- attribute name=class
- attribute value=abc
<div class="abc">This is my other paragraph</div>
Example 3: Multiple attributes
- attribute name=href, class, id
- attribute value=w3cyberlearning.com, abc3, gprivate
<a href="w3cyberlearnings.com" class="abc3" id="gprivate">Learning</a>
Example 4: Multiple class attributes
- attribute name=class
- attribute value=abc and xabc (two values)
<div class="abc xabc">This is my other paragraph</div>
Related Link
- HTML - First Page
- HTML - Elements
- HTML - Comments
- HTML - Attributes