Challenge - 5 Problems
Data Attributes Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
What is the purpose of data attributes in HTML?
Choose the best explanation for why data attributes are used in HTML elements.
Attempts:
2 left
💡 Hint
Think about how you can keep extra info inside HTML without changing how it looks.
✗ Incorrect
Data attributes allow you to store custom data on HTML elements. This data can be read by JavaScript and CSS selectors but does not affect the element's appearance or behavior by itself.
📝 Syntax
intermediate2:00remaining
Which of these is the correct way to add a data attribute to a div element?
Select the valid HTML syntax for adding a data attribute named 'user-id' with value '123' to a <div>.
Attempts:
2 left
💡 Hint
Data attributes always start with 'data-' and use hyphens, not underscores or camelCase.
✗ Incorrect
Data attributes must start with 'data-' followed by lowercase letters and hyphens. The value should be quoted.
❓ rendering
advanced2:00remaining
What will be displayed in the browser for this HTML snippet?
Given the code below, what text will the user see on the page?
HTML
<div data-info="secret">Visible Text</div>
Attempts:
2 left
💡 Hint
Data attributes do not change the visible content unless styled or scripted.
✗ Incorrect
The content inside the <div> is 'Visible Text', which is what the browser shows. The data attribute is invisible by default.
❓ selector
advanced2:00remaining
Which CSS selector targets elements with a data attribute 'role' equal to 'button'?
Choose the correct CSS selector to style elements that have data-role="button".
Attempts:
2 left
💡 Hint
Attribute selectors use square brackets and quotes for exact matches.
✗ Incorrect
The CSS attribute selector syntax is [attribute="value"]. This selects elements with the exact data-role attribute value.
❓ accessibility
expert2:00remaining
Why should you be careful when using data attributes for storing important accessibility information?
Select the best reason why relying solely on data attributes for accessibility data can be problematic.
Attempts:
2 left
💡 Hint
Think about how screen readers read content and attributes.
✗ Incorrect
Assistive technologies do not read data attributes by default. Important accessibility info should use ARIA attributes or semantic HTML.