📖 Scenario: You are creating a simple webpage for a local bakery. The page will have a header, a navigation menu, a main section with a welcome message, and a footer. You want to make sure the HTML uses attributes correctly for accessibility and clarity.
🎯 Goal: Build a basic HTML5 page structure with semantic elements and add appropriate attributes such as lang, charset, viewport, aria-label, and alt to improve accessibility and proper rendering.
📋 What You'll Learn
Use the lang attribute on the <html> tag with value en
Add a <meta> tag with charset set to UTF-8
Add a <meta> tag with name set to viewport and content set to width=device-width, initial-scale=1.0
Add an aria-label attribute to the <nav> element describing it as 'Primary navigation'
Add an alt attribute to the bakery logo image describing it as 'Bakery logo'
💡 Why This Matters
🌍 Real World
Webpages need proper attributes to be accessible to all users, including those using screen readers or mobile devices.
💼 Career
Knowing how to use HTML attributes correctly is essential for front-end developers to build inclusive and well-functioning websites.
Progress0 / 4 steps
1
Create the basic HTML skeleton with lang attribute
Write the opening <!DOCTYPE html> declaration and create the <html> element with the lang attribute set to en. Inside it, add the <head> and <body> elements.
HTML
Hint
The lang attribute helps browsers and screen readers know the language of the page.
2
Add charset and viewport meta tags in the <head>
Inside the <head> element, add a <meta> tag with charset="UTF-8". Then add another <meta> tag with name="viewport" and content="width=device-width, initial-scale=1.0".
HTML
Hint
The charset meta tag sets the character encoding. The viewport meta tag helps with responsive design on mobile devices.
3
Add a <nav> element with an aria-label
Inside the <body>, add a <nav> element. Give it an aria-label attribute with the value Primary navigation. Inside the <nav>, add an unordered list with three links: Home, Menu, Contact.
HTML
Hint
The aria-label attribute describes the navigation region for screen readers.
4
Add a bakery logo image with an alt attribute
Below the <nav>, add an <img> element with src="logo.png" and an alt attribute set to Bakery logo.
HTML
Hint
The alt attribute describes the image for screen readers and shows if the image cannot load.
Practice
(1/5)
1. Which of the following is the best practice for writing HTML attributes?
easy
A. Always use quotes around attribute values, even if not required.
B. Omit quotes to make the code shorter.
C. Use uppercase letters for attribute names.
D. Write attribute values without spaces only.
Solution
Step 1: Understand attribute syntax rules
HTML allows attribute values without quotes only if they contain no spaces or special characters, but quotes improve clarity and prevent errors.
Step 2: Recognize best practice for readability and compatibility
Using quotes consistently around attribute values ensures the code works well across browsers and is easier to read.
Final Answer:
Always use quotes around attribute values, even if not required. -> Option A
Quick Check:
Quotes improve clarity and prevent errors [OK]
Hint: Always put quotes around attribute values for safety [OK]
Common Mistakes:
Skipping quotes causes parsing errors
Using uppercase attribute names (should be lowercase)
Assuming quotes are optional always
2. Which of the following is the correct syntax for adding an alt attribute to an image?
easy
A.
B.
C.
D.
Solution
Step 1: Check attribute value syntax
The alt attribute must have a value describing the image, enclosed in quotes for best practice.
Step 2: Identify the correct option
<img src='photo.jpg' alt='Beautiful sunset'> uses quotes around the descriptive text, making it valid and accessible.
Final Answer:
<img src='photo.jpg' alt='Beautiful sunset'> -> Option B
Quick Check:
Alt text must be quoted and descriptive [OK]
Hint: Alt text always needs quotes and meaningful description [OK]
Common Mistakes:
Leaving alt attribute empty or missing value
Not using quotes around attribute values
Using alt without value or with empty value
3. What will be the rendered result of this HTML snippet?
<button disabled>Click me</button>
medium
A. A clickable button labeled 'Click me'.
B. A button labeled 'disabled' instead of 'Click me'.
C. An error message in the browser.
D. A button labeled 'Click me' that is grayed out and cannot be clicked.
Solution
Step 1: Understand the disabled attribute effect
The disabled attribute on a button makes it inactive and visually grayed out, preventing user interaction.
Step 2: Predict the visual and functional output
The button text remains 'Click me', but the button cannot be clicked and appears disabled.
Final Answer:
A button labeled 'Click me' that is grayed out and cannot be clicked. -> Option D