Skip to content

HTML Tutorial Elements and Attributes

HTML Attributes: Adding Extra Information to Elements

Lesson 8 of 81 2 min read By Deepak Paswan Updated Oct 4, 2026

Attributes give an element extra information. They always go in the opening tag and usually come as a name and a value.

index.html
HTML
<a href="https://example.com" title="A sample website">Visit the example</a>

The a element is a link. It has two attributes:

  • href is the address the link goes to.
  • title is extra text some browsers show when you hover.

The syntax

index.html
HTML
<element name="value" another-name="another value">content</element>
  • Put a space between the tag name and each attribute.
  • Use = between the name and the value.
  • Put the value in quotes. Double quotes are the usual choice.

Attributes you will see a lot

AttributeUsed onMeaning
hrefaThe address a link opens
srcimg, scriptThe file to load
altimgA text description of the image
width, heightimgSize in pixels
langhtml and othersThe language of the content
id, classmost elementsNames for CSS and JavaScript

Attributes without a value

Some attributes are switches. If they are present, they are on.

index.html
HTML
<input type="checkbox" checked>
<button disabled>Not available yet</button>

Quotes and special characters

If a value contains double quotes, wrap it in single quotes, or use &quot;. Keep it simple and avoid quotes inside values where you can.

warning
Missing quotes around values with spaces
<img alt=Red front door> is read as an alt of “Red” plus two stray attributes. Always quote values: alt="Red front door".
lightbulb
Lowercase names
Attribute names are case-insensitive, but lowercase is the convention and avoids confusion.

Exercise: add attributes

Write a link to https://example.org with the text “Read more” that has a title of “Opens the example site”.

Show a possible solution
index.html
HTML
<a href="https://example.org" title="Opens the example site">Read more</a>