1. IDs in HTML and CSS
HTML:
An ID is a unique identifier for a single HTML element.
It is defined using the id
attribute
<div id="header">This is the header</div>
CSS:
In CSS, an id
is targeted using the #
symbol followed by the ID name
#header {
background-color: blue;
color: white;
}
Key Points:
- Uniqueness: An ID must be unique within a page. Only one element can have a specific ID.
- Specificity: IDs have higher specificity than classes. This means styles applied via an ID will override styles applied via a class or tag name.
- Use Case: IDs are typically used for unique elements like headers, footers, or specific sections of a page.
2. Classes in HTML and CSS
HTML:
A class is a reusable identifier for one or more HTML elements.
It is defined using the class
attribute: