HTML Attributes
HTML Attributes
- All HTML elements can have attributes
- Attributes provide additional information about elements
- Attributes are always specified in the start tag
- Attributes usually come in name/value pairs like: name="value"
The <a>(Anchor Tag) tag defines a hyperlink. The href attribute specifies the url of the page and the link goes to:
Example
The src Attribute
The <img> tag is used to embed an image in an HTML page. The src attribute specifies the path to the image to be displayed:
Example
The width and height Attributes
The <img> tag should also contain the width and height attributes, which specifies the width and height of the image (in pixels):
Example
<img src="img_girl.jpg" width="500" height="600">
The alt Attribute
The required alt attribute for the <img> tag specifies an alternate text for an image, if the image for some reason cannot be displayed. This can be due to slow connection, or an error in the src attribute, or if the user uses a screen reader.
Example
<img src="img_girl.jpg" alt="Boy with a jacket">
See what happen if we try to display an image this show does not exist:
The style Attribute
The style attribute is used to add styles to an element, such as color, font, size,font width and many more.
Example
The lang Attribute
You should always include the lang attribute inside the <html> tag, to declare the language of the Web page. This is meant to assist the search engines and browsers.
The following example specifies English as the language:
Example
<!DOCTYPE html>
<html lang="en">
<body>
...
</body>
</html>
Chapter Summary
- All HTML elements can have attributes
- The
hrefattribute of<a>specifies the url of the page the link goes to - The
srcattribute of<img>specifies the path of the image to be displayed - The
widthandheightattributes of<img>provide size information for images - The
altattribute of<img>provides an alternate text for an image - The
styleattribute is used to add styles to an element, such as color, font, size, font width and many more - The
langattribute of the<html>tag declares the language of the Web page - The
titleattribute defines some extra information about an element

1 Comments
Good
ReplyDeletePlease do not enter any spam link in the comment box