The <a> tag designates a hyperlink. The href attribute specifies the URL of the page to which the link directs.
Example
<a href=”https://www.code7schools.com”>Visit code7chools</a> |
The <img> tag is utilized for incorporating images into an HTML page, with the src attribute indicating the image’s file location.
Example
<img src=”img_girl.jpg”> |
There are two methods to specify the URL in the src attribute:
Note: External images may be subject to copyright. Without proper permission, their use may violate copyright laws. Additionally, you have no control over external images; they can be removed or altered unexpectedly.
Tip: It’s generally preferable to use relative URLs. They won’t break if you change domains.
The <img> tag can also include width and height attributes to define the dimensions of the image in pixels.
Example
<img src=”img_girl.jpg” width=”500″ height=”600″> |
The alt
attribute, essential for the <img>
tag, provides alternative text for the image in cases where it cannot be displayed. This could result from slow internet, an error in the src
attribute, or when the content is being accessed through a screen reader.
Example
<img src=”img_girl.jpg” alt=”Girl with a jacket”> |
<img src=”img_typo.jpg” alt=”Girl with a jacket”> |
The style
attribute is utilized for applying various styles to an element, including color, font, size, among others.
<p style=”color:red;”>paragraph.</p> |
It’s recommended to always specify the lang attribute within the <html> tag to indicate the language of the web page, aiding both search engines and browsers.
<!DOCTYPE html> |
The title attribute provides additional details about an element, and its value appears as a tooltip when the element is hovered over with a mouse.
Example
<p title=”I’m a tooltip”>This is a paragraph.</p> |
In HTML, it’s standard to encase attribute values in double quotes, though single quotes are also acceptable. If the value of an attribute includes double quotes, single quotes must be used instead.
Example
<p title=’John “ShotGun” Nelson’> |
Chapter Recap:
All HTML elements can contain attributes.
href
attribute in an <a>
tag defines the destination URL for the hyperlink.src
attribute in an <img>
tag indicates the location of the image to display.width
and height
attributes in an <img>
tag specify the dimensions of the image.alt
attribute in an <img>
tag offers alternative text for the image.style
attribute is employed to apply various styles to an element, like color, font, and size.lang
attribute in the <html>
tag specifies the language of the webpage.title
attribute provides additional information about an element.