1. Attributes
The opening tag can contain
special service information
—
attributes. The closing tag
cannot
have attributes. Attributes look like this:
<tag name1="value1" name2="value2">
Example of a tag with attributes — a link:
<a href="http://codegym.cc/about" target="_blank">
A link to something interesting
</a>
Each attribute is represented as a pair of name
and value
.
There can be as many attributes as you want.
A careful programmer will immediately ask: what to do if the value of an attribute needs to include characters like «<», «>» or quotes?
You can't use them directly inside an HTML document. There are special escape sequences for this:
Character name | Character | HTML escape |
---|---|---|
Double quote | " | " |
Ampersand | & | & |
Less than | < | < |
Greater than | > | > |
Space | | |
Single quote | ' | ' |
This replacement is called character escaping. We'll dive into this topic later on.
2. Images
The <img>
tag
is used to add images to a web page. It's a self-closing tag, meaning
it doesn't have a closing tag
. Important
attributes:
src
— specifies the path to the image.-
alt
— describes the image, which is helpful for search engines and when the image can't be loaded.
Example:
<img src="image.jpg" alt="Image description">
3. Links
The <a>
tag is used to create hyperlinks. The main
attributes of this tag are:
-
href
— specifies the URL of the page or resource the link points to. -
target
— defines where the link is opened (e.g.,_blank
for a new tab).
<a href="https://www.example.com">Go to Example.com</a>
GO TO FULL VERSION