📘 DAY 5: HTML ATTRIBUTES
1️⃣ What is an HTML Attribute?
An HTML attribute provides additional information about an HTML element.
👉 Attributes modify the behavior or appearance of elements.
Example:
Here:
href→ attribute"https://google.com"→ attribute value
2️⃣ Where Are Attributes Written?
Attributes are always written:
Inside the opening tag
After the tag name
Syntax:
3️⃣ Why Do We Use HTML Attributes?
Attributes are used to:
Link pages
Add images
Set styles
Give unique identification
Provide extra information
Without attributes, HTML elements are very limited.
4️⃣ Basic Example of HTML Attributes
src→ source of imagealt→ alternative text
5️⃣ Common HTML Attributes (Most Used)
🔹 href Attribute
Used with <a> tag to define link address.
🔹 src Attribute
Used with <img> to define image source.
🔹 alt Attribute
Provides alternate text for image.
👉 Very important for SEO & accessibility
🔹 title Attribute
Displays tooltip when mouse hovers.
6️⃣ The style Attribute
Used to apply inline CSS.
👉 Not recommended for large projects
👉 Used for quick styling
7️⃣ The id Attribute
Used to uniquely identify an element.
Rules:
Must be unique
One id per element
8️⃣ The class Attribute
Used to group multiple elements.
👉 Used heavily with CSS & JavaScript
9️⃣ Difference Between id and class
| id | class |
|---|---|
| Unique | Reusable |
| One per page | Multiple allowed |
#id in CSS | .class in CSS |
🔟 Global Attributes
Global attributes can be used with any HTML element.
Examples:
idclassstyletitlehidden
1️⃣1️⃣ Attribute Quotes (Important Rule)
Attribute values should be written inside quotes.
✅ Correct:
❌ Incorrect:
1️⃣2️⃣ Multiple Attributes in One Element
You can use more than one attribute.
Order does not matter, but clarity matters.
1️⃣3️⃣ HTML Attributes Are Case-Insensitive
These both work:
✔ Best practice → lowercase
1️⃣4️⃣ Common Beginner Mistakes
❌ Writing attributes outside opening tag
❌ Forgetting quotes
❌ Using same id multiple times
❌ Confusing class and id
1️⃣5️⃣ Practice Examples
Example 1:
Example 2:
1️⃣6️⃣ Interview / Viva Questions
What is an HTML attribute?
Where are attributes written?
Difference between
idandclass?What is a global attribute?
Why is
altattribute important?
1️⃣7️⃣ Summary
Attributes give extra information to elements
Written in opening tag
href,src,altare common attributesidandclassare very importantAttributes improve functionality & accessibility
0 comments:
Post a Comment