HTML Attributes provide Some additional information about HTML elements. HTML Attributes are always specified in the start tag HTML Attributes come in name/value pairs Such As: name="value"
The lang Attribute
The document language can be declared in the <html> tag.
The language is declared in the lang attribute.
Declaring a language is important for accessibility applications (screen readers) and search engines
The first two letters specify the language (en). If there is a dialect, use two more letters (US).
The title Attribute
HTML paragraphs are defined with the <p> tag. In this example, We will See the <p> element has a title attribute. The value of the attribute is "About W3codingwebsite"
HTML CODE EXAMPLE : The Title Attribute
Note : When you move the mouse over the element, the title will be displayed as a tooltip.
The href Attribute
HTML links are describe with the <a> tag. The link address is specified in the href attribute.
HTML CODE EXAMPLE : The href Attribute Under <a> Tag
You will learn more about links and the <a> tag later in this tutorial.
Size Attributes
HTML images are describe with the <img> tag. The source filename put under src as a attribute value , and the size of the image (width and height) are all provided as attributes
HTML CODE EXAMPLE : Size Attributes
The image size is specified in pixels: width="204" means 204 screen pixels wide.
We will learn more about images and the <img> tag later in this tutorial.
The alt Attribute
The alt attribute specifies an alternative text to be used, when an HTML element cannot be displayed for slow network connection .
The value of the attribute can be read by "screen readers".
HTML CODE EXAMPLE : The alt Attribute
We Suggest: Always Use Lowercase Attributes, Because Lower case is the most common And Lower case is easier to type and Always use Quote for Attribute Values.
Note : Using quotes are the most common. Omitting quotes can produce errors. we always use quotes around attribute values.
Single or Double Quotes ?
Double style quotes are the most common in HTML, but single style can also be used in HTML.
In some case, when the attribute value itself contains double quotes, it is necessary to use single quotes
HTML CODE EXAMPLE : Use Double Quotes Under Single Quotes
Or vice versa:
HTML CODE EXAMPLE : Use Single Quotes Under Double Quotes
All HTML elements can have attributes
The HTML title attribute provides additional "tool-tip" information
The HTML href attribute provides links address information
The HTML width and height attributes provide size information
The HTML alt attribute provides text for screen readers
Always use lowercase HTML attribute names
we always quote attributes with double quotes
Below we Provide a list of some attributes often used in HTML:
| Attribute | Description |
|---|---|
| alt | Specifies an alternative text for an image |
| href | Specifies the URL (web address) for a link |
| disabled | Specifies that an input element should be disabled |
| id | Specifies a unique id for an element |
| style | Specifies an inline CSS style for an element |
| src | Specifies the URL (web address) for an image |
| value | Specifies the value (text content) for an input element. |
| title | Specifies extra information about an element (displayed as a tool tip) |