📖 Scenario: You are creating a simple webpage for a local bakery. The page will have a header, a main section with a welcome message, and a footer. To style and link these sections easily later, you need to assign unique IDs to each main part of the page.
🎯 Goal: Build a basic HTML page with a <header>, <main>, and <footer> element. Assign the exact ID attributes page-header, main-content, and page-footer to these elements respectively.
📋 What You'll Learn
Use semantic HTML5 elements: <header>, <main>, and <footer>.
Assign the ID page-header to the <header> element.
Assign the ID main-content to the <main> element.
Assign the ID page-footer to the <footer> element.
Include a <title> in the <head> with the text 'Bakery Home'.
Use proper HTML5 document structure with lang, charset, and viewport meta tags.
💡 Why This Matters
🌍 Real World
Assigning IDs to HTML elements helps web developers target specific parts of a webpage for styling with CSS or interaction with JavaScript.
💼 Career
Understanding and using the ID attribute is fundamental for front-end web development, enabling you to build accessible, maintainable, and interactive websites.
Progress0 / 4 steps
1
Create the basic HTML structure
Write the basic HTML5 skeleton with lang="en" in the <html> tag, and include <head> with <meta charset="UTF-8">, <meta name="viewport" content="width=device-width, initial-scale=1.0">, and a <title> with the text Bakery Home. Then add empty <header>, <main>, and <footer> elements inside the <body>.
HTML
Hint
Start by typing the standard HTML5 document structure. Don't forget the lang attribute in the <html> tag and the meta tags inside <head>.
2
Add ID to the header element
Add the ID attribute page-header to the existing <header> element in the HTML code.
HTML
Hint
Inside the <header> tag, add id="page-header".
3
Add ID to the main element
Add the ID attribute main-content to the existing <main> element in the HTML code.
HTML
Hint
Inside the <main> tag, add id="main-content".
4
Add ID to the footer element
Add the ID attribute page-footer to the existing <footer> element in the HTML code.
HTML
Hint
Inside the <footer> tag, add id="page-footer".
Practice
(1/5)
1. What is the main purpose of the id attribute in HTML?
easy
A. To uniquely identify one element on the page
B. To add a class to multiple elements
C. To create a hyperlink to another page
D. To add inline styles to an element
Solution
Step 1: Understand the role of the id attribute
The id attribute is used to give a unique name to one element on the page.
Step 2: Compare with other attributes
Unlike classes, which can be shared by many elements, id must be unique and identifies only one element.
Final Answer:
To uniquely identify one element on the page -> Option A
Quick Check:
ID attribute = unique element identifier [OK]
Hint: ID is for one unique element only [OK]
Common Mistakes:
Thinking ID can be used on multiple elements
Confusing ID with class attribute
Using ID to add styles to many elements
2. Which of the following is the correct way to add an ID to a div element?
easy
A.
B.
C.
D.
Solution
Step 1: Check correct syntax for ID attribute
The ID attribute must be written as id='value' with quotes around the value.
Step 2: Identify the correct option
<div id='header'></div> uses correct syntax with quotes and equals sign. <div id header></div> misses equals sign, and D uses wrong colon syntax.
Final Answer:
<div id='header'></div> -> Option D
Quick Check:
ID attribute syntax = id='value' [OK]
Hint: ID attribute needs quotes and equals sign [OK]
Common Mistakes:
Omitting quotes around ID value
Using colon instead of equals sign
Confusing class and ID syntax
3. What will be the visible result in the browser for this HTML snippet?
The snippet uses id='main' on two different div elements, which breaks the rule that IDs must be unique.
Step 2: Verify other syntax
Tags are properly closed, attribute names are correct, and ID values can be any string, so no other errors apply.
Final Answer:
Using the same ID on multiple elements -> Option B
Quick Check:
ID must be unique per element [OK]
Hint: Each ID must be unique on the page [OK]
Common Mistakes:
Reusing same ID on multiple elements
Confusing ID with class for multiple elements
Thinking ID values must be numeric
5. You want to create a navigation menu where each link scrolls to a different section on the same page. Which is the correct way to use the id attribute to achieve this?
hard
A. Assign unique IDs to each section and use <a href='#id'> to link
B. Use the same ID on all sections and link with <a href='#id'>
C. Use classes on sections and link with <a href='.class'>
D. Use inline styles to scroll to sections
Solution
Step 1: Understand linking with IDs
To link to a part of the page, each target section must have a unique id attribute.
Step 2: Use anchor links with href='#id'
The links use href='#id' to jump to the section with that ID. Using unique IDs ensures correct navigation.
Final Answer:
Assign unique IDs to each section and use <a href='#id'> to link -> Option A