Progress:0%
HTML Basics 5 min readLesson 3 of 3

HTML Attributes

Learn how attributes provide additional information about HTML elements.

### HTML Attributes Attributes provide extra information about HTML elements. They are always specified in the start tag in name/value pairs like: name="value".

Common Attributes 1. `href` — Used in `<a>` tags to specify destination URL. 2. `src` — Used in `<img>` tags to specify image path. 3. `alt` — Provides alt text for accessibility and broken images. 4. `style` — Adds inline CSS styling. 5. `class` & `id` — Target elements with CSS and JavaScript.

html
<a href="https://www.thecodebrains.com" target="_blank">Visit TheCodeBrains</a>
<img src="hero.jpg" alt="Hero Image" width="500" height="300">
```

Interactive Sandbox

HTML Attributes Interactive Demo

Live W3-Editor

Edit code below and see instant live output in the preview box

Source Code InputHTML / CSS / JS
Live Browser Result Live Result

Test Yourself With Exercises

Verify your understanding before moving to the next topic

Chapter Quiz

Which attribute specifies an alternate text for an image if the image cannot be displayed?