HTML ATTRIBUTES
- HTML attributes are used to add more information to an HTML Element. Important Things to Remember HTML. attributes are found in HTML tags.
- HTML attributes only appear at start tags. It will never be on end tags. HTML elements can have multiple attributes.
- HTML attributes are composed of name/value pairs.
- There are some attributes that can be used on all HTML Elements though they may not have effects on some elements. They are called Global Attributes.
- An HTML attribute is composed of an attribute name. an equal sign a value surrounded by quotation marks "value".
- It looks like this: attribute name="value"
- You can also use single quotation marks depending on the situation esp. when the value contains double quotes.
Attribute LANG Example:
<!DOCTYPE> <html> <html lang="en-US"> </html> |
- We use the lang attribute to define the language of an HTML file.
- The language defined above is American English.
Attribute href Example:
<a href="http://www.example.com"> |
- Links are defined using the anchor <a> element.
- On the example above we used the href attribute to tell the browser where to go.
- When clicked the user will be redirected to http://www.example.com.
Attribute title Example:
<a href="http://www.example.com" title="html attribute title"> |
Output:
http://www.example.com
- The title attribute provides a html attribute title
- Unfortunately, it doesn't work on mobile devices. If you want to see how it works
Attribute style Example:
<p style="font-size: 40px; color: blue"> I am a paragraph with a size of 40 pix. </p> |
Output:
I am a paragraph with a font-size of 40 pix.
- On the example given above we have created a paragraph using the <p> element.
- We also used the style attribute to change its font-size and color.
Attributes id and class Example
<div class="name"> <!--some content goes here --> </div> <div class="name"> <!--some content goes here --> </div> <div id="name"> <!--some content goes here --> </div> |
The id and class attributes give references to elements inside an HTML document.
Multiple elements can have the same class values/names, The id's value should be unique for each clement.