📖 Scenario: You are creating a simple webpage with a header, a main section, and a footer. You want to make sure the page is accessible and easy to navigate by adding global attributes to the HTML elements.
🎯 Goal: Build a basic HTML page structure using semantic elements and add global attributes like id, class, and tabindex to improve accessibility and styling.
📋 What You'll Learn
Use semantic HTML5 elements: <header>, <main>, and <footer>
Add an id attribute to the <header> element with the value page-header
Add a class attribute to the <main> element with the value content-area
Add a tabindex attribute to the <footer> element with the value 0
Ensure the HTML document includes the lang attribute in the <html> tag and the charset meta tag
💡 Why This Matters
🌍 Real World
Web developers use global attributes to improve accessibility, styling, and scripting on all HTML elements.
💼 Career
Understanding global attributes is essential for creating accessible and maintainable websites, a key skill for front-end developers.
Progress0 / 4 steps
1
Create the basic HTML structure
Write the basic HTML5 skeleton with html, head, and body tags. Include the lang attribute with value en in the <html> tag. Inside the head, add a meta tag with charset set to UTF-8. Do not add any content inside the body yet.
HTML
Hint
Remember to add lang="en" inside the <html> tag and a meta tag with charset="UTF-8" inside the <head>.
2
Add semantic sections with global attributes
Inside the body, add a header element with an id attribute set to page-header. Then add a main element with a class attribute set to content-area. Leave the footer element for the next step.
HTML
Hint
Use id="page-header" on the header and class="content-area" on the main element.
3
Add the footer with tabindex attribute
Add a footer element after the main element. Give the footer a tabindex attribute with the value 0. Inside the footer, add a paragraph with the text Contact us at info@example.com.
HTML
Hint
Use tabindex="0" on the footer to make it focusable by keyboard.
4
Add a class to the footer for styling
Add a class attribute with the value site-footer to the existing footer element.
HTML
Hint
Add class="site-footer" inside the footer tag.
Practice
(1/5)
1. Which of the following is a global attribute that can be used on any HTML element to give it a unique identifier?
easy
A. alt
B. src
C. id
D. href
Solution
Step 1: Understand what a global attribute is
Global attributes can be used on any HTML element regardless of its type.
Step 2: Identify the attribute that uniquely identifies elements
The id attribute assigns a unique identifier to an element, usable on all elements.
Final Answer:
id -> Option C
Quick Check:
Unique element identifier = id [OK]
Hint: Use id for unique element IDs on any tag [OK]
Common Mistakes:
Confusing src as global (it's for images, scripts)
Thinking href works on all elements (only links)
Using alt outside images
2. Which is the correct way to add a tooltip text to an HTML element using a global attribute?
easy
A. tooltip="Info"
B. title="Info"
C. alt="Info"
D. data-tooltip="Info"
Solution
Step 1: Identify the attribute that shows tooltip text
The title attribute is a global attribute that shows a tooltip on hover.
Step 2: Check the syntax correctness
title="Info" is the correct syntax to add tooltip text.
Final Answer:
title="Info" -> Option B
Quick Check:
Tooltip attribute = title [OK]
Hint: Use title for tooltips on any element [OK]
Common Mistakes:
Using non-existent tooltip attribute
Confusing alt (only for images)
Using custom data attributes for tooltips without scripts
3. What will be the visible effect of this HTML snippet in a browser?
A. The button element cannot have global attributes
B. The id attribute value is invalid
C. The class attribute cannot be used with hidden
D. The hidden attribute should not have a value
Solution
Step 1: Review the hidden attribute usage
The hidden attribute is a boolean attribute and should not have a value like "false"; presence means true.
Step 2: Check other attributes for correctness
id and class are valid global attributes on button. The error is only with hidden="false".
Final Answer:
The hidden attribute should not have a value -> Option D
Quick Check:
Boolean attributes have no value = hidden no value [OK]
Hint: Boolean global attributes never have values, just presence [OK]
Common Mistakes:
Giving boolean attributes values like "true" or "false"
Thinking hidden="false" means visible
Believing class and hidden conflict
5. You want to store extra information about a product in an HTML element without affecting its display or behavior. Which global attribute should you use?
hard
A. data-product-info
B. title
C. hidden
D. class
Solution
Step 1: Understand storing extra info in HTML
Custom data attributes starting with data- allow storing extra info without affecting display or behavior.
Step 2: Identify the correct attribute for product info
data-product-info is a valid custom data attribute to hold product details invisibly.
Final Answer:
data-product-info -> Option A
Quick Check:
Extra info storage = data-* attributes [OK]
Hint: Use data-* attributes to store hidden info [OK]
Common Mistakes:
Using title which shows visible tooltip
Using hidden which hides element
Using class which is for styling, not data
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.