Tags give a web browser only basic information about types of elements. Attributes are used to add more specific and varied instructions. Attributes are written inside of the start tag. For example, you can specify a URL for the link using the href
attribute in the <a>
tag like this: <a href="index.html">
.
There are two types of attributes:
href
for <a>
, src
for <img>
style
, class
and id
Some tags always require attributes. For example, the <a>
tag needs the href
attribute. Without the href
attribute, you cannot make a link to another web page. Also, the <img>
tag needs the src
attribute. Without the src
attribute, you cannot display your intended image.
There are optional attributes that can be used to add more instructions. For example, the target
attribute is used for the <a>
tag to define how to open the link. When you specify the attribute as target="_blank"
, you can open the linked page in a new tab in the browser.
We haven't explained these tags and attributes yet, but will do so in the next chapter.
A global attribute is an attribute that can be used in any tag. The most commonly used global attributes are style
, class
, and id
, which are mainly used for CSS. How to use these attributes will be explained later.
Tags give a web browser only basic information about types of elements. Attributes are used to add more specific and varied instructions. Attributes are written inside of the start tag. For example, you can specify a URL for the link using the href
attribute in the <a>
tag like this: <a href="index.html">
.
There are two types of attributes:
href
for <a>
, src
for <img>
style
, class
and id
Some tags always require attributes. For example, the <a>
tag needs the href
attribute. Without the href
attribute, you cannot make a link to another web page. Also, the <img>
tag needs the src
attribute. Without the src
attribute, you cannot display your intended image.
There are optional attributes that can be used to add more instructions. For example, the target
attribute is used for the <a>
tag to define how to open the link. When you specify the attribute as target="_blank"
, you can open the linked page in a new tab in the browser.
We haven't explained these tags and attributes yet, but will do so in the next chapter.
A global attribute is an attribute that can be used in any tag. The most commonly used global attributes are style
, class
, and id
, which are mainly used for CSS. How to use these attributes will be explained later.