HTML & CSS
/Beginner
HTML Attributes
Definition
Special words used inside the opening tag of an HTML element to control the element's behavior or provide additional information.
Explain Like I'm New
If an HTML tag is a noun (like a Dog), an attribute is an adjective (like 'Brown'). You add attributes to tags to configure them. For example, an `<img>` tag is useless without the `src` attribute telling it WHICH image to load.
Real World Example
`<a href="https://google.com">`. The `href` attribute tells the link where to go. `<img src="cat.jpg" alt="A cute cat">`. The `src` and `alt` attributes configure the image.
Common Use Cases
- •Linking to URLs
- •Defining image sources
- •Adding CSS classes/IDs
Interactive Example
Interview Questions
basic
- Where are attributes placed in an HTML tag?
intermediate
- What is the difference between the `id` and `class` attributes?