Attributes provide additional information about HTML elements.
- 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"
The href Attribute
HTML links are defined with the
<a> tag. The link address is specified in the
<a href="https://www.learncomputer.in">This is a link.</a>
You will learn more about links and the
<a> tag later in this tutorial.
The src Attribute
HTML images are defined with the
The filename of the image source is specified in the
The width and height Attributes
HTML images also have
height attributes, which specifies the width and height of the image:
<img src="img_girl.jpg" width="500" height="600">
You will learn more about attributes in a later chapter.
You will learn more about images in our HTML Images chapter.
The alt Attribute
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.
<img src="img_girl.jpg" alt="Girl with a jacket">
The HTML Style Attribute
Setting the style of an HTML element, can be done with the
style attribute has the following syntax:
The property is a CSS property. The value is a CSS value.