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.
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.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.
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.
href, not HREF.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.
| Attribute | Value | Description |
|---|---|---|
href | a web address | Where a link goes to. |
src | a file path | Which image, video, or script to load. |
alt | text | Text shown if an image cannot load, and read out by screen readers. |
class | one or more names | Groups elements so CSS can style them together. |
id | one name | Gives one single element a unique name on the page. |
style | CSS rules | Styles one element directly. |
title | text | Extra 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>
<input disabled> means the input is switched off — the word disabled alone is the whole attribute. These are called boolean attributes.title="Raj's page".HREF — always use small letters.href = "…" — it works, but nobody writes it that way.alt attribute on images — it is required, not optional.<!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.<!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>
Change the code below and press Run to see the result instantly. No file to save, no login needed.
The questions learners ask most about this lesson — read the question, then open it to see the answer.
Extra information about an element. It sits inside the start tag in the form name equals value, usually inside double quotes.
It gives the address a link goes to, for example a link to kamaldnp.com.
Unquoted values break when they contain a space. For example, title equals My Photo without quotes reads only My as the value.
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?
2. Which attribute tells a link where to go?
3. Which attribute tells an image which picture to load?
4. What should you always put around attribute values?
5. What is the alt attribute for?
Read the question first, try to answer it in your own words, then open it to check. These are the questions interviewers actually ask.
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.
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.
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.
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.
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".
<!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>
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.
Finish all 35 lessons, pass the test (80%), pay ₹10 and get your certificate.
Take the testPrefer watching? Video courses teach the same topics step by step.
Free tutorials teach you the basics. Our paid courses add live projects, mentorship and a certificate.
Browse all coursesAsk about courses, website & more
Request human callback:
Please log in to download. You will stay on this page after logging in!
New here? Register now →