0
0
HTMLmarkup~20 mins

Data attributes in HTML - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Data Attributes Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the purpose of data attributes in HTML?
Choose the best explanation for why data attributes are used in HTML elements.
ATo replace the use of class and id attributes for styling purposes.
BTo store extra information on elements that can be accessed by CSS and JavaScript without affecting the layout or presentation.
CTo add inline styles directly to elements for quick design changes.
DTo create hyperlinks between different parts of the page.
Attempts:
2 left
💡 Hint
Think about how you can keep extra info inside HTML without changing how it looks.
📝 Syntax
intermediate
2: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>.
A<div data-user-id="123"></div>
B<div data_user_id="123"></div>
C<div dataUserId="123"></div>
D<div data-userid=123></div>
Attempts:
2 left
💡 Hint
Data attributes always start with 'data-' and use hyphens, not underscores or camelCase.
rendering
advanced
2: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>
AVisible Text
Bsecret
Cdata-info="secret"
DNothing will be displayed
Attempts:
2 left
💡 Hint
Data attributes do not change the visible content unless styled or scripted.
selector
advanced
2: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".
Adata-role=button
B.data-role-button
C#data-role=button
D[data-role="button"]
Attempts:
2 left
💡 Hint
Attribute selectors use square brackets and quotes for exact matches.
accessibility
expert
2: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.
AData attributes cause validation errors in HTML5.
BData attributes slow down page loading significantly.
CData attributes are not automatically recognized by assistive technologies like screen readers.
DData attributes cannot be styled with CSS.
Attempts:
2 left
💡 Hint
Think about how screen readers read content and attributes.