0
0
CSSmarkup~5 mins

Attribute selectors in CSS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an attribute selector in CSS?
An attribute selector lets you select HTML elements based on the presence or value of an attribute. For example, you can style all links with a specific href or all inputs with a certain type.
Click to reveal answer
beginner
How do you select elements with a specific attribute regardless of its value?
Use the syntax [attribute]. For example, input[required] selects all input elements that have the required attribute, no matter its value.
Click to reveal answer
intermediate
What does the selector a[href^='https'] do?
It selects all <a> elements whose href attribute value starts with https. The ^= means 'starts with'.
Click to reveal answer
intermediate
Explain the difference between [attr$='value'] and [attr*='value'] selectors.
[attr$='value'] selects elements whose attribute ends with 'value'. [attr*='value'] selects elements whose attribute contains 'value' anywhere inside.
Click to reveal answer
advanced
How can attribute selectors improve accessibility and user experience?
They allow styling elements based on attributes like aria-* or disabled, helping users understand element states visually. For example, styling disabled buttons differently.
Click to reveal answer
Which CSS selector matches all input elements with a type attribute equal to "checkbox"?
Ainput[type^='checkbox']
Binput[type$='checkbox']
Cinput[type='checkbox']
Dinput[type*='checkbox']
What does the selector a[href$='.pdf'] select?
AAll <code>&lt;a&gt;</code> elements with href starting with '.pdf'
BAll <code>&lt;a&gt;</code> elements with href exactly '.pdf'
CAll <code>&lt;a&gt;</code> elements with href containing '.pdf' anywhere
DAll <code>&lt;a&gt;</code> elements with href ending with '.pdf'
Which selector matches elements with an attribute named 'data-info' regardless of its value?
A[data-info]
B[data-info='']
C[data-info^='']
D[data-info$='']
What does the selector input[required] do?
ASelects inputs with required attribute set to true
BSelects inputs with required attribute present, no matter the value
CSelects inputs with any value for required attribute
DSelects inputs without required attribute
Which attribute selector matches elements whose attribute contains a specific word?
A[attr~='word']
B[attr$='word']
C[attr*='word']
D[attr^='word']
Describe how you would use CSS attribute selectors to style all links that open in a new tab.
Think about the attribute that controls opening links in new tabs.
You got /3 concepts.
    Explain the difference between the attribute selectors [attr^='value'], [attr$='value'], and [attr*='value'].
    Focus on where the value appears in the attribute.
    You got /3 concepts.