SA-21/06, C-11, Asapur, Varanasi, UP support@kamaldnp.com +91 8318013442
HTML
1. HTML Introduction: What is HTML? Learn with Examples 2. Best Free HTML Editors: Notepad to VS Code for Beginners 3. HTML Basic Structure: Doctype, Head, Body Explained 4. HTML Elements Explained: Tags, Content & Empty Elements 5. HTML Attributes List: href, src, alt, width, title & More 6. HTML Headings h1 to h6: Which Heading Tag to Use When 7. HTML Paragraphs: p Tag, br Line Breaks & pre Text 8. HTML Style Attribute: Colour, Font Size & Alignment 9. HTML Text Formatting Tags: bold, italic, mark & More 10. HTML Comments: How to Add Notes & Hide Code in HTML 11. HTML Colors: Names, HEX, RGB & HSL Colour Codes 12. HTML CSS: Inline, Internal & External Stylesheets 13. HTML Links: a Tag, href, New Tab & Email Links 14. HTML Images: img Tag, src, alt, Width & Formats 15. HTML Favicon: Create & Add a Browser Tab Icon 16. HTML Title Tag: How to Write a Good Page Title 17. HTML Tables: table, tr, th, td, colspan & rowspan 18. HTML Lists: ul, ol, dl & Nested Lists Explained 19. HTML Block vs Inline Elements: div, p, span Explained 20. HTML Div Tag: Group Content & Build Page Layouts 21. HTML Class Attribute: Style Many Elements at Once 22. HTML id Attribute: Unique IDs, Links, CSS & JavaScript 23. HTML Iframes: Embed YouTube, Maps & Pages in HTML 24. HTML JavaScript: script Tag, Clicks & First Example 25. HTML File Paths: Relative vs Absolute Paths Explained 26. HTML Head Element: title, meta, charset & viewport 27. HTML Layout: header, nav, main, footer Page Structure 28. HTML Responsive Design: Viewport, Images & Media Queries 29. Semantic HTML Tags: header, nav, main, article & footer 30. HTML Forms: input, label, select, checkbox & Submit 31. HTML Entities: & < > © with Examples 32. HTML Audio & Video Tags: controls, source & Fallback 33. HTML Accessibility: alt Text, Labels, Landmarks & ARIA 34. HTML Meta Tags & SEO: charset, viewport, OG Tags 35. HTML Quotations: blockquote, q, cite, abbr & address
Final Test — Certificate ₹10
Try this code live
Lesson 5 of 35

HTML Attributes List: href, src, alt, width, title & More

4 min read · Free · No login needed

Attributes give extra information about an element. They always sit inside the start tag, in the form name="value". The value is usually written inside double quotes.

Diagram — see how it fits together
Infographic: parts of an HTML attribute

Common attributes

  • href — the address a link goes to: <a href="https://kamaldnp.com">Visit us</a>
  • src — the file an image or script loads: <img src="photo.jpg">
  • alt — text shown if an image cannot load, and read by screen readers.
  • width and height — the size of an image in pixels.
  • title — a small tooltip that appears when the mouse hovers over the element.
  • style — CSS written directly on the element.

Quotes matter

Always put attribute values in quotes. Double quotes are the standard. Single quotes also work, but mixing them or leaving them out causes bugs — especially when the value itself contains spaces. For example, href=https://kamaldnp.com without quotes may work, but title=My Photo without quotes breaks, because the browser reads only My as the value.

Every element has attributes

Almost every HTML element accepts the global attributes — id, class, style, and title. You will use id and class constantly when you start styling pages with CSS, so remember them now.

Tip: Attribute names are not case-sensitive, but the convention is to write them in lowercase: href, not HREF.

What an attribute is

An attribute is extra information you add to a tag. It always sits inside the start tag, after the tag name, and it always has a name and a value: name="value". Attributes change how an element behaves or looks — a link needs href to know where to go, and an image needs src to know which picture to show.

Common attributes

AttributeValueDescription
hrefa web addressWhere a link goes to.
srca file pathWhich image, video, or script to load.
alttextText shown if an image cannot load, and read out by screen readers.
classone or more namesGroups elements so CSS can style them together.
idone nameGives one single element a unique name on the page.
styleCSS rulesStyles one element directly.
titletextExtra information, shown as a small tooltip when you hover.

Here is the same link written two ways. The first is correct. The second works in most browsers, but it is bad practice and breaks easily if the address ever contains a space.

<a href="https://kamaldnp.com">Visit KAMALDNP</a>
<a href=https://kamaldnp.com>Visit KAMALDNP</a>
Note: Some attributes have no value at all. For example, <input disabled> means the input is switched off — the word disabled alone is the whole attribute. These are called boolean attributes.
Tip: Always use double quotes around values. Single quotes work too, but double quotes are the standard, and they are the only safe choice when a value itself contains an apostrophe, like title="Raj's page".

Common mistakes

  • Leaving values unquoted — it breaks the moment a value contains a space.
  • Using capital letters in attribute names, like HREF — always use small letters.
  • Putting a space before or after the equals sign, like href = "…" — it works, but nobody writes it that way.
  • Forgetting the alt attribute on images — it is required, not optional.

Example explained

  • <!DOCTYPE html>, <html>, <head> and <title>Attributes</title> — the usual page skeleton. The title shows on the browser tab.
  • <a href="https://kamaldnp.com" ...>KAMALDNP Academy</a> — a link. The href attribute tells the browser where the link goes; the text between the tags is what the visitor clicks.
  • title="Visit KAMALDNP" — a second attribute on the same link. It shows a small tooltip when the mouse hovers over the link.
  • <img src="logo.png" ...> — an image. The src attribute tells the browser which picture file to load. The tag has no end tag.
  • alt="KAMALDNP logo" — the text shown if the picture cannot load, and the text a screen reader reads out for blind visitors.
  • width="120" height="120" — two more attributes on the same image. They fix its size to 120 pixels wide and 120 pixels tall.

Example

Example
<!DOCTYPE html>
<html>
<head>
<title>Attributes</title>
</head>
<body>

<a href="https://kamaldnp.com" title="Visit KAMALDNP">KAMALDNP Academy</a>
<p><img src="logo.png" alt="KAMALDNP logo" width="120" height="120"></p>

</body>
</html>

Output

Output — how it looks in the browser
Output of HTML Attributes List: href, src, alt, width, title & More

Try it yourself — live editor

Change the code below and press Run to see the result instantly. No file to save, no login needed.

Result

Frequently asked questions

The questions learners ask most about this lesson — read the question, then open it to see the answer.

1. What is an HTML attribute?

Extra information about an element. It sits inside the start tag in the form name equals value, usually inside double quotes.

2. What does the href attribute do?

It gives the address a link goes to, for example a link to kamaldnp.com.

3. Why must attribute values be in quotes?

Unquoted values break when they contain a space. For example, title equals My Photo without quotes reads only My as the value.

Check yourself — did you get it?

Finished the lesson? Test yourself with 5 quick questions — you get the answer instantly, with the reason for each one.

1. Where do attributes always sit?

Attributes always sit inside the start tag, in the form name="value".

2. Which attribute tells a link where to go?

href holds the address a link goes to: <a href="https://kamaldnp.com">.

3. Which attribute tells an image which picture to load?

src gives the file an image loads: <img src="photo.jpg">.

4. What should you always put around attribute values?

Double quotes are the standard. Unquoted values break the moment a value contains a space.

5. What is the alt attribute for?

alt is the text shown if an image cannot load, and screen readers read it aloud.

Interview questions — can you answer these?

Read the question first, try to answer it in your own words, then open it to check. These are the questions interviewers actually ask.

1. What is an HTML attribute?

Extra information about an element, written inside the start tag in the form name="value". For example, in <a href="https://kamaldnp.com">, href is the attribute and the web address is its value.

2. What is the difference between href and src?

href is used by links (<a>) to say where the link goes. src is used by images, videos and scripts to say which file to load. A link needs href; an image needs src.

3. Why should attribute values always be in double quotes?

Because an unquoted value breaks the moment it contains a space. For example, title=My Photo without quotes breaks — the browser reads only "My" as the value. Double quotes are the standard and always safe.

Try it yourself — build this

Reading is not enough — now build it yourself. Write the code in the live editor, run it, check the hint if you get stuck, and open the solution only after you have tried.

1. Link and image

Create a page with a link to https://kamaldnp.com (the link text must be "Visit KAMALDNP") and an image with src="photo.jpg" and alt="My photo".

Hint: The link needs href; the image needs src and alt. Put every value in double quotes.
Open the live editor
Show solution
<!DOCTYPE html>
<html>
<head>
<title>Links and Images</title>
</head>
<body>
<h1>My Favourite Website</h1>
<p><a href="https://kamaldnp.com">Visit KAMALDNP</a></p>
<img src="photo.jpg" alt="My photo">
</body>
</html>

Why learn this yourself — and not just ask AI?

AI can write code for you, but it cannot think for you. When you learn HTML yourself, your brain builds the real skill: you understand why a page looks the way it does, you can fix it when it breaks, and you can answer it in an exam or an interview without help. That is the skill that gets you a job — not a copied answer.

Get certified — just ₹10

Finish all 35 lessons, pass the test (80%), pay ₹10 and get your certificate.

Take the test

Prefer watching? Video courses teach the same topics step by step.

Go further with a full course

Free tutorials teach you the basics. Our paid courses add live projects, mentorship and a certificate.

Full Stack PHP Development Course 2026
₹3,000
View
Summer Training in Python Programming 2026
₹3,000
View
Summer Industrial Training in MERN Stack 2026
₹3,000
View
Browse all courses
HTML — Lessons
1. HTML Introduction: What is HTML? Learn with Examples 2. Best Free HTML Editors: Notepad to VS Code for Beginners 3. HTML Basic Structure: Doctype, Head, Body Explained 4. HTML Elements Explained: Tags, Content & Empty Elements 5. HTML Attributes List: href, src, alt, width, title & More 6. HTML Headings h1 to h6: Which Heading Tag to Use When 7. HTML Paragraphs: p Tag, br Line Breaks & pre Text 8. HTML Style Attribute: Colour, Font Size & Alignment 9. HTML Text Formatting Tags: bold, italic, mark & More 10. HTML Comments: How to Add Notes & Hide Code in HTML 11. HTML Colors: Names, HEX, RGB & HSL Colour Codes 12. HTML CSS: Inline, Internal & External Stylesheets 13. HTML Links: a Tag, href, New Tab & Email Links 14. HTML Images: img Tag, src, alt, Width & Formats 15. HTML Favicon: Create & Add a Browser Tab Icon 16. HTML Title Tag: How to Write a Good Page Title 17. HTML Tables: table, tr, th, td, colspan & rowspan 18. HTML Lists: ul, ol, dl & Nested Lists Explained 19. HTML Block vs Inline Elements: div, p, span Explained 20. HTML Div Tag: Group Content & Build Page Layouts 21. HTML Class Attribute: Style Many Elements at Once 22. HTML id Attribute: Unique IDs, Links, CSS & JavaScript 23. HTML Iframes: Embed YouTube, Maps & Pages in HTML 24. HTML JavaScript: script Tag, Clicks & First Example 25. HTML File Paths: Relative vs Absolute Paths Explained 26. HTML Head Element: title, meta, charset & viewport 27. HTML Layout: header, nav, main, footer Page Structure 28. HTML Responsive Design: Viewport, Images & Media Queries 29. Semantic HTML Tags: header, nav, main, article & footer 30. HTML Forms: input, label, select, checkbox & Submit 31. HTML Entities: & < > © with Examples 32. HTML Audio & Video Tags: controls, source & Fallback 33. HTML Accessibility: alt Text, Labels, Landmarks & ARIA 34. HTML Meta Tags & SEO: charset, viewport, OG Tags 35. HTML Quotations: blockquote, q, cite, abbr & address
Final Test — Certificate ₹10

🤖 KAMALDNP AI Assistant

Ask about courses, website & more

Hi! I'm KAMALDNP AI Assistant. Ask me about our courses, website features, or anything else! 😊
Please wait 5s...
🤖 KAMALDNP Assistant ✕

Request human callback:

🔐 Login Required
✕

Please log in to download. You will stay on this page after logging in!

New here? Register now →