Lesson 8: HTML Attributes & Advanced Elements
HTML Attributes & Advanced Elements
Lesson 08 · Giving your HTML elements more power.
What are HTML attributes?
So far, you've learned how to create headings, paragraphs, links, images, lists, forms, and more. But HTML elements can do even more!
Attributes provide additional information about an HTML element. They are written inside the opening tag.
In this example:
- a is the HTML element.
- href is the attribute.
- "https://example.com" is the attribute value.
The id attribute
The id attribute gives an element a unique identifier. Think of it like giving an element its own name tag.
You can use an ID to target a specific element with CSS or JavaScript. An ID should be unique on the page.
The class attribute
A class lets you give the same label to multiple elements. This is useful when you want several elements to share the same design.
You can style every element with that class:
What's the difference?
Example: a unique page heading.
Example: several cards with the same design.
Other attributes you'll use
title — provides extra information, often shown when someone hovers over an element.
style — adds CSS directly to an element.
target — controls where a link opens.
disabled — prevents an input or button from being used.
placeholder — displays a hint inside an empty input.
Custom data attributes
HTML also allows you to store extra information using attributes that begin with data-.
JavaScript can read these values using an element's dataset property.
The details and summary elements
Sometimes you want information to stay hidden until someone chooses to open it. HTML has two elements that can do this without JavaScript.
Try it below:
Click to reveal the secret!
You've just used the details and summary elements!
The progress element
The progress element displays the progress of a task.
Example:
The meter element
The meter element displays a measurement within a known range.
Your turn: Build a profile card!
Use what you've learned to create a simple profile card. Your card should include:
- A heading with an ID.
- A paragraph with a class.
- A link with an href attribute.
- A button with a title attribute.
- A details section with hidden information.
Here's a starter template. Try filling in the missing parts!
Test your knowledge!
Choose the correct answer for each question.