HTML attributes provide extra information about HTML elements. In this lesson,
you will learn what HTML attributes are, how they work, the most commonly used
HTML attributes, and best practices for writing clean, SEO-friendly HTML.
What Are HTML Attributes?
HTML attributes are special words added inside the opening tag of an HTML element.
They provide extra details about how an element should behave, where it should link,
what image it should display, what style it should use, or how it should be identified.
<tagname attribute="value">Content</tagname>
In most cases, an attribute has a name and a value. The attribute name describes
the type of information, and the value defines the actual setting.
HTML Attribute Syntax
HTML attributes are written inside the opening tag. Attribute values are usually
written inside double quotes.
<a href="https://www.example.com">Visit Example</a>
<img src="html-logo.png" alt="HTML logo" />
<p class="highlight">This paragraph uses a class attribute.</p>
In these examples, href, src, alt, and
class are attributes.
Top 10 Most Used HTML Attributes
The following table shows the most commonly used HTML attributes beginners should know.
These attributes are used frequently in links, images, forms, styling, accessibility,
SEO, and JavaScript-based interactions.
#
Attribute
Used With
Purpose
Example
1
href
<a>
Defines the destination URL of a link.
<a href="/tutorials/html/">HTML Tutorial</a>
2
src
<img>, <script>
Specifies the source file path.
<img src="html-logo.png" alt="HTML logo" />
3
alt
<img>
Provides alternative text for images.
<img src="logo.png" alt="Company logo" />
4
id
Most HTML elements
Defines a unique identifier for an element.
<section id="about">About</section>
5
class
Most HTML elements
Groups elements for CSS styling or JavaScript.
<p class="lead">Intro text</p>
6
style
Most HTML elements
Adds inline CSS styles.
<p style="font-weight: bold;">Bold text</p>
7
title
Most HTML elements
Adds extra tooltip information.
<abbr title="HyperText Markup Language | PHPKINGDOM">HTML</abbr>
Global attributes are attributes that can be used on most HTML elements.
They are useful for styling, accessibility, scripting, identification, and user interaction.
id: gives an element a unique identifier.
class: groups elements for styling or scripting.
style: adds inline CSS styles.
title: provides additional tooltip text.
lang: defines the language of content.
hidden: hides an element from display.
tabindex: controls keyboard focus order.
data-*: stores custom data for JavaScript.
HTML Link Attributes
Link attributes control where a link goes and how it behaves. The most important
link attribute is href.
Avoid unnecessary inline styles when CSS classes are better.
Use rel="noopener noreferrer" with external links opened in a new tab.
Use form attributes like required, type, and name correctly.
Common HTML Attribute Mistakes
Using duplicate id values on the same page.
Forgetting alt text for important images.
Using vague image descriptions like image or photo.
Opening links with target="_blank" without rel.
Using inline style everywhere instead of CSS classes.
Forgetting the name attribute in form inputs.
Key Takeaways
HTML attributes provide extra information about HTML elements.
Attributes are written inside the opening tag.
Common attributes include href, src, alt, id, and class.
Good attribute usage improves SEO, accessibility, styling, and JavaScript behavior.
Always use clean, meaningful, and valid attributes in your HTML pages.
Pro Tip
The alt, href, title, lang, and
aria-label attributes can directly improve accessibility and content clarity.
You now understand HTML attributes, their syntax, common examples, and best practices.
Next, learn how HTML headings help organize content and improve SEO.