HTML Attributes


HTML attributes provide additional information about HTML elements. Attributes are always written inside the opening tag and usually come in name and value pairs.

Attributes help control how an element behaves, looks, or links to other resources.

Basic Syntax of HTML Attributes

Attributes are written inside the opening tag using this format:

tagname attribute="value"

Most attributes require a value, and the value is written inside quotes.

In the example above:

  • title is the attribute name
  • The text inside quotes is the attribute value
  • The attribute provides extra information about the paragraph

When you hover over the text, the browser shows the title message.

The href Attribute

The <a> tag is used to create links. The href attribute specifies the destination URL where the link should go.

In this example:

  • <a> defines a hyperlink
  • href specifies the URL of the page
  • The link text is what users see and click

The src Attribute

The <img> tag is used to display images on a webpage. The src attribute specifies the path to the image file.

In this example:

  • src defines the image file location
  • alt provides alternative text if the image cannot be displayed
  • The alt attribute is important for accessibility and SEO

Important Rules for HTML Attributes

  • Attributes are written inside opening tags
  • Attribute names are not case-sensitive
  • Attribute values should be written inside quotes
  • Multiple attributes can be used in one element

Why HTML Attributes Matter for Jobs

In real-world projects, attributes are used for links, images, forms, styling hooks, and JavaScript interaction.

Understanding attributes is essential for writing clean HTML, improving accessibility, and working with CSS and JavaScript efficiently.

What You Will Learn Next

In the next lesson, you will learn about the tools required to write and run HTML code, including editors and browsers.