Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Welcome to Topic 1.5! ⚡
In the previous lesson, you mastered HTML Elements—the basic building blocks of any webpage. Now, imagine you have a plain button or a link on your page. How do you tell the computer:
The answer is: HTML Attributes! Attributes give tags extra information and superpowers.
An Attribute provides additional settings, properties, or behavior to an HTML element.
Let us understand this with a simple real-life example: Your School ID Card! 🪪
Just like your ID card gives extra details about who you are, HTML attributes give extra instructions about how an element should behave.
Every beginner must remember these 4 simple rules:
name="value"."...").Here are the most essential attributes every web developer uses every single day:
href Attribute (For Links)The <a> tag creates clickable hyperlinks. The href (Hypertext Reference) attribute tells the browser which web address (URL) to open when someone clicks the link:
If you don't provide an href attribute, the link has nowhere to go!
src Attribute (For Images)The <img> tag displays a picture on your screen. The src (Source) attribute tells the browser where to find the image file:
src can be a file on your computer (like myphoto.png) or a link from the internet (like https://example.com/logo.png).alt Attribute (Alternate Description for Images)The alt attribute provides a text description of the image.
Why is alt so important?
alt text aloud to describe the picture!width and height Attributes (Setting Image Dimensions)You can control the size of images using width and height (measured in pixels):
title Attribute (The Tooltip Helper)When you add a title attribute to any element, a small floating text box (called a tooltip) appears whenever a user hovers their mouse cursor over that element!
target Attribute (Open in a New Tab)By default, clicking a link replaces the current webpage. If you want the link to open in a fresh new browser tab, use target="_blank":
lang Attribute (Declaring Page Language)As you saw in the boilerplate lesson, the lang attribute is used inside the <html> root tag to tell search engines and translation tools the language of the page:
| Attribute | Used In Tags | What It Specifies | Example |
|---|---|---|---|
href | <a> | Link destination URL | <a href="https://google.com"> |
src | <img>, <video>, <script> | Path or URL to the file | <img src="pic.jpg"> |
alt | <img> | Alternate description text | <img alt="School Logo"> |
width / height | <img>, <video> | Size dimensions in pixels | <img width="300"> |
title | Any tag | Mouse hover tooltip text | <h1 title="Welcome!"> |
target | <a> | Where to open the link | <a target="_blank"> |
lang | <html> | Document language | <html lang="en"> |
Some special HTML attributes do not need a "value". Their mere presence inside a tag turns on that feature! These are called Boolean Attributes.
disabled: Turns off an input field or button so users cannot click or type into it.required: Makes an input field mandatory in a form (user cannot submit without filling it).readonly: Users can read the text but cannot edit or change it.</p title="Hello"><p title="Hello"><a href=https://google.com><a href="https://google.com"><img scr="photo.jpg"> (Many beginners type scr instead of src!)<img src="photo.jpg"><img src="photo.jpg", alt="Photo", width="200"><img src="photo.jpg" alt="Photo" width="200">name="value".href for link destinations and src for image paths.alt to describe images for screen readers and slow connections.target="_blank" to open links in a new browser tab.disabled and required) do not require values.Test your understanding with these multiple-choice questions:
<a> tag)?alt attribute important for image tags?disabled or required?target attribute opens a link in a fresh, new browser tab?index.html file in VS Code.<body>, try adding:target="_blank" so it opens in a new tab:src, alt, and width:title attribute:Ctrl + S) and view your interactive webpage live with Live Server! 🚀In the next lesson, we will continue your web development journey with HTML Headings (Heading & Paragraphs).
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Elements | HTML Headings |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.