0
0
CSSmarkup~20 mins

Attribute selectors in CSS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Attribute Selector Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
selector
intermediate
2:00remaining
Which CSS rule selects all elements with a 'type' attribute exactly equal to 'text'?
Given the following HTML snippet:
<input type="text" name="username">
<input type="password" name="password">
<input type="text" name="email">

Which CSS selector will style only the inputs where type is exactly text?
Ainput[type="text"] { border: 2px solid blue; }
Binput[type*="text"] { border: 2px solid blue; }
Cinput[type^="text"] { border: 2px solid blue; }
Dinput[type$="text"] { border: 2px solid blue; }
Attempts:
2 left
💡 Hint
The selector should match elements whose attribute value is exactly the given string.
selector
intermediate
2:00remaining
Which selector matches elements with a 'data-role' attribute that starts with 'admin'?
Consider these HTML elements:
<div data-role="admin-user">User</div>
<div data-role="administrator">Admin</div>
<div data-role="guest">Guest</div>

Which CSS selector will style only the first two divs?
Adiv[data-role*="admin"] { background-color: yellow; }
Bdiv[data-role$="admin"] { background-color: yellow; }
Cdiv[data-role^="admin"] { background-color: yellow; }
Ddiv[data-role="admin"] { background-color: yellow; }
Attempts:
2 left
💡 Hint
Look for the selector that matches attribute values starting with a specific string.
selector
advanced
2:00remaining
What is the visual effect of this CSS rule?
a[href$='.pdf'] { color: red; }
Given this CSS:
a[href$='.pdf'] { color: red; }

And these links:
<a href="file.pdf">PDF File</a>
<a href="document.pdf?version=2">PDF Version 2</a>
<a href="image.png">Image</a>

Which links will appear red in the browser?
ANo links will be red because the selector is invalid.
BBoth links with href containing '.pdf' anywhere will be red.
CAll links will be red because they all have href attributes.
DOnly the link with href exactly ending with '.pdf' (file.pdf) will be red.
Attempts:
2 left
💡 Hint
The $= selector matches attribute values that end with the given string exactly.
accessibility
advanced
2:00remaining
Which attribute selector helps improve accessibility by styling only form inputs that have a 'required' attribute?
You want to visually highlight all form fields that are required by the user.
Which CSS selector correctly targets all inputs with the 'required' attribute, regardless of its value?
Ainput[required] { outline: 2px solid red; }
Binput[required="true"] { outline: 2px solid red; }
Cinput[required^="true"] { outline: 2px solid red; }
Dinput[required$="true"] { outline: 2px solid red; }
Attempts:
2 left
💡 Hint
The presence selector matches elements that have the attribute, no matter its value.
🧠 Conceptual
expert
2:00remaining
How many elements will be selected by this CSS?
button[aria-pressed="true"]
Given this HTML:
<button aria-pressed="true">On</button>
<button aria-pressed="false">Off</button>
<button aria-pressed>Unknown</button>
<button>No attribute</button>

How many buttons will the selector button[aria-pressed="true"] match?
A4
B1
C3
D2
Attempts:
2 left
💡 Hint
The selector matches elements with the attribute exactly equal to the string 'true'.