Aral Code

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>
  • href is 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

AttributeUsed onWhat 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
titleAny elementExtra info shown as a tooltip on hover
lang<html> and othersThe language of the content
idAny elementA unique name for one element
classAny elementA group name shared by many elements
styleAny elementQuick 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.

Example src, alt, width and height
<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.)

Example Hover over the bold words
<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

  1. Put them in the opening tag only. Never in the closing tag. </a href="..."> is wrong.
  2. Use quotes around values. HTML sometimes works without quotes, but values with spaces will break. Always quote to be safe.
  3. Separate attributes with a space. <img src="a.jpg" alt="A cat"> — notice the space between them.
  4. Use lowercase names. Write href, not HREF.
  5. Don't repeat an attribute in the same tag. If you write two class attributes, 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:

Example disabled and checked
<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. 🙂

1. Where do attributes go?
2. Which attribute tells a link where to go?
3. Which line is written correctly?
4. Which is a boolean attribute that needs no value?

By Sir Reyel · Last updated 2026-12-04