HTML attributes provide additional information about HTML elements.
HTML Attributes
- All HTML elements can have attributes
- Attributes provide additional information about elements
- Attributes are always specified in the start tag
- Attributes usually come in name/value pairs like: name="value"
The href Attribute
The Visit our HTML tutorial
Bad:
Sometimes you have to use quotes. This example will not display the title attribute correctly, because it contains a space:
At W3Schools we always use quotes around attribute values.
Single or Double Quotes?
Double quotes around attribute values are the most common in HTML, but single quotes can also be used.
In some situations, when the attribute value itself contains double quotes, it is necessary to use single quotes:
Or vice versa:
Chapter Summary
- All HTML elements can have attributes
- The
href
attribute of - The
src
attribute of - The
width
andheight
attributes ofprovide size information for images
- The
alt
attribute of - The
style
attribute is used to add styles to an element, such as color, font, size, and more - The
lang
attribute of thetag declares the language of the Web page
- The
title
attribute defines some extra information about an element
HTML Exercises
Test Yourself With Exercises
Exercise:
Add a "tooltip" to the paragraph below with the text "About W3Schools".
W3Schools is a web developer's site.
Start the Exercise
HTML Attribute Reference
A complete list of all attributes for each HTML element, is listed in our: HTML Attribute Reference.