Nearby lessons
3 of 24🔖 HTML Attributes
📌 What are HTML Attributes?
HTML attributes give extra information about elements. They are added inside the start tag, usually as name/value pairs like name="value".
Attributes are like extra settings for HTML elements. They help define how an element behaves or appears. They are always written in the opening tag, like this: <p style="color:red">.
📋 Common HTML Attributes
| Attribute | Description |
|---|---|
href | 🔗 Sets the URL for a link |
src | 🖼️ Sets the image file path |
width & height | 📐 Set image or element size |
alt | 📝 Text shown if image can't load |
style | 🎨 Adds inline CSS styling |
lang | 🌐 Sets the page language |
title | 💡 Tooltip shown on hover |
class | 🏷️ Assigns a class name |
id | 🆔 Gives a unique ID to the element |
data-* | 📦 Stores custom data in an element |
✅ Attribute Best Practices
- ✔️ Always use quotes:
name="value"(not justname=value) - ✔️ Use
altfor images to support accessibility - ✔️ Use
titleto give helpful tooltips on hover - ✔️ Prefer
classwith external CSS instead ofstyle - ✔️ Use
rel="noopener noreferrer"withtarget="_blank"for security - ✔️ Add
loading="lazy"to images to improve page speed - ✔️ Always set the
langattribute in the<html>tag (likelang="en")
💻 HTML Attributes
Example04
🧠 Test Your Knowledge
5 QuestionsProgress: 0 / 5