HTML & CSS Course
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?

Flash Cards

Question

Where are they placed?

Click to reveal answer
Answer

Always in the OPENING tag. Never in the closing tag.

Question

id vs class?

Click to reveal answer
Answer

The `id` attribute MUST be completely unique on the page (like a Social Security Number). The `class` attribute can be reused on hundreds of elements (like a uniform).