Skip to main content

HTML Attributes

By SamK
0
0 recommends
Topic(s)

HTML attributes provide additional information about HTML elements. 

The are specified in the HTML tags. 

Attributes can be added to all HTML tags and elements.

Elements can have multiple attributes.

Attributes are always specified in the start tag.

Attributes are mostly defined in the form of name/value pairs like: attrname="value".

It is strongly recommended to use quotes ' ' or double quotes " " to enclose attribute values because, in some cases they may cause errors.

Attributes are case insensitive, but it is strongly recommended by W3C to use lowercase attributes.

Examples:

The style attribute is used to specify styles for an HTML element, for example:

<p style="font-weight:bold;">This is a paragraph</p>

The href attribute in the <a> element defines the link URL, for example: 

<a href="https://www.webmastermaze.com">WebmasterMaze</a>

The src attribute in the <img> element defines the image URL, for example:

<img src="image.png">

The width and height attributes in the <img> element define the width and height of the image, for example:

<img src="image.png" width="100" height="100">

The required alt attribute for the <img> tag specifies an alternate text for an image, which is shown if the user uses a screen reader or the image could not be loaded, for example:

<img src="image.png" alt="Image">

The lang attribute is used to define the language of the web page in the <html> tag, for example:

<html lang="en">

There are many other attributes as well, which will be covered in later tutorials.