Attributes

Frontend SELF EN
Level 1 , Lesson 5
Available

1. Attributes

The opening tag can contain special service informationattributes. The closing tag cannot have attributes. Attributes look like this:


<tag name1="value1" name2="value2">  

Example of a tag with attributes — a link:

HTML
      
<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 " &quot;
Ampersand & &amp;
Less than < &lt;
Greater than > &gt;
Space &nbsp;
Single quote ' &#39;

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:

HTML
      
<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).
HTML
      
<a href="https://www.example.com">Go to Example.com</a>
      
    
1
Task
Frontend SELF EN, level 1, lesson 5
Locked
Fixing Errors in HTML
Fixing Errors in HTML
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION