Learn one of the most powerful programming languages in the world and become a rockstar developer.
Attributes define additional characteristics or properties of the element such as width and height of an image. Attributes are always specified in the start tag (or opening tag) and usually consists of name/value pairs like
name="value". Attribute values should always be enclosed in quotation marks.
Also, some attributes are required for certain elements. For instance, an
<img> tag must contain a
alt attributes. Let's take a look at some examples of the attributes usages:
HTML links are defined with the
<a> tag. The link address is specified in the
<a href="https://www.adzetech.com">This is a link</a>
You will learn more about links and the
<a> tag later in this tutorial.
HTML images are defined with the
The filename of the image source is specified in the
HTML images also have
height attributes, which specifies the width and height of the image:
The width and height are is specified in pixels by default; so width="500" means 500 pixels wide.
<img src="img_girl.jpg" width="500" height="600">
You will learn more about images in our HTML Images chapter.
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.
style attribute allows you to specify CSS styling rules such as color, font, border, etc. directly within the element. Let's check out an example to see how it works:
<p style="color: blue;">This is a paragraph.</p> <img src="images/sky.jpg" style="width: 300px;" alt="Cloudy Sky"> <div style="border: 1px solid red;">Some content</div>
You will learn more about styling HTML elements in HTML styles chapter.
The attributes we've discussed above are also called global attributes..
A complete list of attributes for each HTML element is listed inside HTML5 tag reference.