DETAILS

HTML Attributes

HTML Attributes Photo

HTML Attributes

HTML Attributes

All HTML elements can have attributes. Attributes provide additional information about an element. Attributes are always specified in the start tag. Attributes usually come in name/value pairs like name=”value”.

1. The href Attribute:
HTML links are defined with the <a> tag. The link address is specified in the href attribute:

CODE

The href Attribute

RESULT:

value

2.The src Attribute:-

HTML images are defined with the <img> tag. The filename of the image source is specified in the src attribute.

CODE:

The src Attribute

RESULT:

HTML

 

3.The width and height attributes:
HTML images also have width and height attributes, which specifies the width and height of the image: As we insert image and define height and width like above img source attributes.

CODE:

HTML

RESULT:

The width and height attributes

4.The alt Attribute:
The alt attribute specifies an alternative text to be used if an image cannot be displayed.

The value of the alt attribute can be read by screen readers. This way, someone “listening” to the webpage, e.g. a vision-impaired person, can “hear” the element. The alt attribute is also useful if the image cannot be displayed (e.g. if it does not exist):

CODE:

The alt Attribute

RESULT:

Result

 

5.The style Attribute:
The style attribute is used to specify the styling of an element, like color, font, size, etc.

CODE:

The style Attribute

RESULT:

RESULT6.HTML  lang Attribute:
This attribute is used to specify the language of the element content. Some examples of languages are en for English, es for Spanish, etc

CODE:

HTML  lang Attribute

RESULT:

RESULT

7.The title Attribute
Here, a title attribute is added to the <p> element. The value of the title attribute will be displayed as a tooltip when you mouse over the paragraph:

CODE:

The title Attribute

RESULT:

RESULT

8. We Suggest: Quote Attribute Values:
The HTML standard does not require quotes around attribute values. The href attribute, demonstrated above, can be written without quotes:

GOOD:

We Suggest

 

BAD:

BAD

 

9.Single or Double Quotes?
Double quotes around attribute values are the most common in HTML, but single quotes can also be used. In some situations, when the attribute value itself contains double quotes, it is necessary to use single quotes: Here is the example using both quotes.

CODE:

Single or Double Quotes

RESULT:

RESULT

HTML Attributes:
Below is an alphabetical list of some attributes often used in HTML, which you will learn more about in this tutorial:HTML Attributes