Q1. What is the id attribute in HTML?
The id attribute provides a unique identifier for an HTML element, used for CSS styling, JavaScript, and anchor links.
Q2. What are the rules for id values?
id must be unique in a page, cannot contain spaces, should start with a letter, and can include letters, digits, hyphens, underscores.
Q3. How do you link to a specific element by id?
Use the # symbol in href: <a href="#section2">Go to Section 2</a> links to element with id="section2".
Q4. How do you select an element by id in CSS?
Use hash (#) followed by id: #my-id { property: value; } selects the unique element with that id.
Q5. Can multiple elements have the same id?
No, id must be unique. Duplicate ids cause invalid HTML and unexpected behavior in CSS and JavaScript.
