Getting Started Lesson 5 of 42
HTML Attributes — Adding Extra Information to Elements
Learn what HTML attributes are, how to write them correctly with quotes, and the most common ones like href, src, alt, title, lang, id and class.
Tags tell the browser what something is. Attributes give extra details about it. A link needs to know where it goes. An image needs to know which picture to show. That extra information is written as attributes.
How attributes look
Attributes always go inside the opening tag, after the element name. Each one has a name, an equals sign, and a value in quotes:
<a href="https://www.pagasa.dost.gov.ph">Check the weather</a>
hrefis the attribute name."https://www.pagasa.dost.gov.ph"is the attribute value.
In plain words: "This is a link (a), and its destination (href) is the PAGASA website."
Common attributes you will use often
| Attribute | Used on | What it does |
|---|---|---|
href | <a> | The address a link goes to |
src | <img>, <audio>, <video> | The file to load |
alt | <img> | Text that describes an image |
width, height | <img>, <video> | The size in pixels |
title | Any element | Extra info shown as a tooltip on hover |
lang | <html> and others | The language of the content |
id | Any element | A unique name for one element |
class | Any element | A group name shared by many elements |
style | Any element | Quick CSS styling for that one element |
Example: an image with attributes
An image element is empty — it has no content — so all its information comes from attributes.
<img src="/img/jeepney.svg" alt="A red jeepney with a Cubao–Quiapo route sign" width="320" height="200">
Try changing width="320" to width="160" in the editor. The picture becomes smaller. Now change src to /img/mango.svg and see the image change completely.
The title attribute
title adds a small tooltip that appears when you hover your mouse over the element. It's handy for abbreviations and extra hints. (On phones there is no hover, so don't put important information only in a title.)
<p>Our school follows the <strong title="Department of Education">DepEd</strong> calendar.</p>
<p>Typhoon updates come from <strong title="Philippine Atmospheric, Geophysical and Astronomical Services Administration">PAGASA</strong>.</p>
Rules for writing attributes
- Put them in the opening tag only. Never in the closing tag.
</a href="...">is wrong. - Use quotes around values. HTML sometimes works without quotes, but values with spaces will break. Always quote to be safe.
- Separate attributes with a space.
<img src="a.jpg" alt="A cat">— notice the space between them. - Use lowercase names. Write
href, notHREF. - Don't repeat an attribute in the same tag. If you write two
classattributes, the browser ignores the second.
Double quotes or single quotes?
Both work: alt="photo" and alt='photo'. Double quotes are more common. Use single quotes only when the value itself contains a double quote, like title='He said "Mabuhay!"'.
Boolean attributes
A few attributes don't need a value at all. Just writing the name turns the feature on. These are called boolean attributes. You'll meet them in forms and media:
<p><input type="checkbox" checked> I attended the flag ceremony</p>
<p><input type="checkbox" disabled> This box cannot be clicked</p>
<p><button disabled>Submit (closed)</button></p>
id and class — a preview
id gives an element a unique name, like a student ID number — no two elements on a page should share the same id. class is like a section name: many students can belong to "Grade 10 – Rizal." Both are used mostly with CSS and JavaScript. They get their own lesson later.
Quick Quiz
Check what you learned. Walang grade ito, practice lang. 🙂
By Sir Reyel · Last updated 2026-12-04