back to home

Attributes

  1. Attributes are used to provide additional information about HTML elements.
  2. All HTML elements can have attributes
  3. Attributes are always specified in the start tag
  4. Attributes usually come in name/value pairs like: name="value"
  5. The HTML5 standard does not require quotes(" ") around attribute values. But it is necessary to use quotes.
    "< p title=About W3Schools>< /p>" This example will not display the title attribute correctly, because it contains a space
Attributes Works
href The link address is specified in the "href" attribute.
< a href="https://www.w3schools.com"> This is a link < /a>
src The filename of the image source is specified in the src attribute.
< img src="img_girl.jpg" >
width and height HTML images have width and height attributes, which specifies the width and height of the image
< img src="img_girl.jpg" width="500" height="600" >
Here, width="500" means 500 pixels wide.
alt The alt attribute specifies an alternative text to be used, if an image cannot be displayed (e.g. if it does not exist).
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" >
style The style attribute is used to specify the styling of an element, like color, font, size etc. Ex:
works code
Text Color: < p style="color:red">This is a red paragraph.< /p>
Background Color: < body style="background-color:powderblue;">< /body>
Tomato
Orange
DodgerBlue
MediumSeaGreen
Gray
SlateBlue
Violet
LightGray
Customized Font: < h1 style="font-family:verdana;">This is a heading< /h1>
Customized Text-Size: < p style="font-size:160%;">This is a paragraph.< /p>
Text Alignment < p style="text-align:center;">Centered paragraph.< /p>

You can also use more than 2 style attributes like this:
< p style="border: 2px solid black; background-color: aqua;">< /p>

lang The language is declared with the lang attribute.
The language of the document can also be declared in the < html> tag.
Declaring a language is important for accessibility applications (screen readers) and search engines.
< html lang="en-US">< /html>
The first two letters specify the language (en). If there is a dialect, add two more letters (US).
title The value of the title attribute will be displayed as a tooltip when you mouse over the paragraph.
< p title="I'm a tooltip"> This is a paragraph. < /p>
disabled Specifies that an input element should be disabled
id Specifies a unique id for an element. For Details
class For Details
Reference from back to top