Elements can be configured by their attributes.
The following code shows an attribute that applies to the a element.
I like <a href="/index.htm">CSS</a> and HTML.
a
element lets you create a hyperlink that,
when it's clicked on, loads a different HTML document.
The code above uses double quotes "/index.htm"
to delimit the attribute value.
You can also use single quotes '/index.htm'
.
To specify a value for an attribute containing quotes,
you use both styles "my 'HTML' value"
or 'my "HTML" value'
.
Attributes have a name and a value.
In the code above the name of the attribute is href
.
Its value is /index.htm
.
Attributes can be added only to start tags or single tags
Attributes can never be added to end tags.
There are a set of global attributes that can be applied to any HTML element
Elements can define their own attributes that provide configuration information specific to the element.
For example, the href
attribute is local to the a
element.
It configures the URL for the hyperlink.
You can apply multiple attributes to an element by separating them with one or more space characters.
The following code adds multiple attribute to the a
element.
I like <a class="myClass" href="/index.htm" id="myID">HTML</a> and CSS.
The order of the attributes is not important.
In the code above both class
and id
are global attributes.
You can mix global attributes with the element's specific attributes.
Boolean attributes are attributes without value.
The disable
in the following code is a boolean attribute.
Enter what you like: <input disabled>
The disabled attribute stops the user from entering data.
You can define the same boolean attribute by assigning the empty string ("") or by setting the value to be the name of the attribute.
<input disabled=""> <input disabled="disabled">