Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is a naming convention in CSS?
A naming convention is a set of rules to name CSS classes and IDs clearly and consistently so that the code is easy to read and maintain.
Click to reveal answer
beginner
Why use the BEM naming convention?
BEM (Block Element Modifier) helps organize CSS by naming classes to show their role and relationship, making styles easier to understand and avoid conflicts.
Click to reveal answer
intermediate
Example of a BEM class name for a button inside a header block with a modifier for a large size?
header__button--large
Click to reveal answer
beginner
What is the benefit of using lowercase and hyphens in CSS class names?
Using lowercase letters and hyphens makes class names easy to read and type, and it avoids errors caused by case sensitivity.
Click to reveal answer
beginner
What should you avoid when naming CSS classes?
Avoid using vague names, spaces, special characters, or names that are too long or too short. Names should be meaningful and consistent.
Click to reveal answer
Which of these is a correct BEM class name for a modifier?
AbuttonActive
Bbutton--active
Cbutton_active
Dbutton.active
✗ Incorrect
BEM uses double hyphens for modifiers, like 'button--active'.
Why is it important to follow naming conventions in CSS?
ATo increase file size
BTo make code harder to read
CTo keep code consistent and easy to maintain
DTo avoid using classes
✗ Incorrect
Consistent naming helps everyone understand and maintain the CSS code easily.
Which is a good practice for CSS class names?
AUse lowercase letters and hyphens
BUse uppercase letters randomly
CUse special characters like @ or #
DUse spaces in class names
✗ Incorrect
Lowercase letters and hyphens improve readability and avoid errors.
In BEM, what does the 'Element' part represent?
AA CSS property
BA standalone block
CA modifier state
DA part inside a block
✗ Incorrect
Elements are parts inside a block, separated by double underscores.
Which of these is NOT recommended for CSS class names?
AVery long and complicated names
BMeaningful names
CConsistent style
DUsing hyphens to separate words
✗ Incorrect
Very long names make code harder to read and maintain.
Explain the BEM naming convention and why it helps in CSS.
Think about how BEM breaks down parts of a component.
You got /5 concepts.
List three best practices for naming CSS classes.
Focus on readability and avoiding errors.
You got /5 concepts.
Practice
(1/5)
1. Which of the following is the best practice for naming CSS classes?
easy
A. Use camelCase, like mainHeader.
B. Use uppercase letters and underscores, like Main_Header.
C. Use lowercase letters and hyphens to separate words, like main-header.
D. Use spaces between words, like main header.
Solution
Step 1: Understand common CSS naming styles
CSS classes should be easy to read and consistent. Lowercase with hyphens is widely accepted.
Step 2: Compare options
Use lowercase letters and hyphens to separate words, like main-header. uses lowercase and hyphens, which is recommended. Options B and C use uppercase or camelCase, less common in CSS. Use spaces between words, like main header. uses spaces, which is invalid in class names.
Final Answer:
Use lowercase letters and hyphens to separate words, like main-header. -> Option C
Quick Check:
Lowercase + hyphens = best CSS naming [OK]
Hint: Use lowercase and hyphens for CSS classes [OK]
Common Mistakes:
Using spaces in class names
Using uppercase letters
Using camelCase instead of hyphens
2. Which CSS class name follows the BEM naming convention?
easy
A. button--primary
B. button_primary
C. buttonPrimary
D. button primary
Solution
Step 1: Recall BEM naming rules
BEM uses block__element--modifier format. Double hyphens separate modifiers.
Step 2: Identify correct format
button--primary uses double hyphens for modifier --primary, matching BEM. Options A and B use camelCase or underscores, not BEM. button primary uses space, invalid in class names.
Final Answer:
button--primary -> Option A
Quick Check:
BEM modifier uses double hyphens [OK]
Hint: BEM modifiers use double hyphens (--modifier) [OK]
Common Mistakes:
Using underscores instead of hyphens
Using camelCase for BEM
Using spaces in class names
3. Given this CSS class name: card__title--large, what does it represent in BEM?
medium
A. Block: card, Modifier: title, Element: large
B. Modifier: card, Block: title, Element: large
C. Element: card, Block: title, Modifier: large
D. Block: card, Element: title, Modifier: large
Solution
Step 1: Break down the BEM parts
In card__title--large, card is the block, title is the element (after double underscore), and large is the modifier (after double hyphen).
Step 2: Match parts to options
Block: card, Element: title, Modifier: large correctly identifies block, element, and modifier. Other options mix these parts incorrectly.
Final Answer:
Block: card, Element: title, Modifier: large -> Option D
Quick Check:
BEM = block__element--modifier [OK]
Hint: BEM: block__element--modifier order [OK]
Common Mistakes:
Confusing element and modifier positions
Mixing block and element names
Ignoring double underscores and hyphens
4. Identify the error in this CSS class name: nav__item_active
medium
A. Class name is too long
B. Underscore used instead of double hyphen for modifier
C. Spaces are used instead of underscores
D. Double underscore missing between block and element
Solution
Step 1: Check BEM syntax
BEM requires modifiers to be separated by double hyphens --, not underscores.
Step 2: Analyze the class name
The class nav__item_active uses a single underscore for the modifier, which is incorrect. It should be nav__item--active.
Final Answer:
Underscore used instead of double hyphen for modifier -> Option B
Quick Check:
Modifier separator = double hyphen [OK]
Hint: Modifiers need double hyphens, not underscores [OK]
Common Mistakes:
Using single underscore for modifiers
Forgetting double underscore between block and element
Using spaces in class names
5. You want to create CSS classes for a card component with a title and a highlighted state using BEM. Which naming set is correct?
hard
A. card, card__title, card--highlighted
B. card, card_title, card_highlighted
C. card, card-title, card-highlighted
D. card, card__title--highlighted, card__highlighted
Solution
Step 1: Understand BEM structure for blocks, elements, and modifiers
Block is card. Element is card__title. Modifier on block is card--highlighted.
Step 2: Evaluate options
card, card__title, card--highlighted correctly uses BEM naming. card, card_title, card_highlighted uses underscores, not BEM. card, card-title, card-highlighted uses hyphens but not BEM format. card, card__title--highlighted, card__highlighted incorrectly applies modifier to element and duplicates modifier.