Tutorials /HTML /HTML Attributes

HTML Attributes

HTML Attributes Tutorial

HTML attributes provide additional information about HTML elements.

All HTML elements can have attributes.
Attributes are always specified in the start tag.
Attributes usually come in name/value pairs like: name="value"

The href Attribute

The <a> tag defines a hyperlink. The href attribute specifies the URL:

<a href="https://www.w3schools.com">Visit W3Schools</a>

The src Attribute

The <img> tag embeds an image. The src attribute defines the image path:

<img src="img_girl.jpg">
Use relative URLs for images inside your project.
Use absolute URLs for external images.

Width and Height Attributes

Use width and height to define image size:

<img src="img_girl.jpg" width="500" height="600">

The alt Attribute

The alt attribute provides alternate text for the image:

<img src="img_girl.jpg" alt="Girl with a jacket">

The style Attribute

Add CSS directly using style attribute:

<p style="color:red;">This is a red paragraph.</p>

The lang Attribute

Use lang in <html> to define page language:

<html lang="en"> ... </html>
You can also define country code like lang="en-US"

The title Attribute

Shows a tooltip on hover:

<p title="I'm a tooltip">This is a paragraph.</p>

Best Practices

✅ Use lowercase for attribute names
✅ Always quote attribute values using double or single quotes

Examples with quotes

<a href="https://www.w3schools.com/html/">Good</a>
<a href=https://www.w3schools.com/html/>Bad</a>

Sometimes, you must use quotes due to spaces:

<p title='John "ShotGun" Nelson'>

Chapter Summary

  • All HTML elements can have attributes
  • href defines link URL
  • src defines image path
  • width and height define image size
  • alt provides alternative text
  • style applies inline CSS
  • lang defines page language
  • title shows tooltips


The Coding Journey provides high-quality, beginner-friendly, and advanced web development tutorials. Learn React, Next.js, JavaScript, Tailwind CSS, and more with hands-on projects. Build faster, code smarter, and level up your skills! 🚀

© 2025 All Rights Reserved | The coding journey