Naming and component boundaries
Definition and purpose
Naming conventions make style ownership and intended reuse explicit. BEM-style names, utilities and locally scoped components are design choices, not special CSS syntax.
Named component parts
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } .card__title { color: blue; } </style> </head> <body> <article class="card"> <h2 class="card__title" id="a">News</h2> <p class="card__body" id="b">Read more</p> </article> <h2 id="outside">Outside</h2> </body></html>Only the named title becomes blue.
Syntax and mental model
A block such as card names a component, card__title names a part, and card--featured names a variant. A utility such as u-center describes a narrow reusable operation. Component-scoped systems can generate names or use boundaries such as Shadow DOM. Naming alone cannot prevent global selectors or inherited values from reaching a component. Document who owns each rule and keep modifier specificity manageable.
A narrow utility
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } .u-center { text-align: center; } .card__title { color: green; } </style> </head> <body> <article class="card"> <h2 class="card__title" id="a">News</h2> <p class="card__body u-center" id="b">Read more</p> </article> <h2 id="outside">Outside</h2> </body></html>The utility changes alignment without taking ownership of the entire card.
Common mistakes
Avoid styling every h2 just to change a card title. Also avoid long chains that depend on exact DOM depth; a part class is less coupled to markup nesting.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Reset and normalization. Next lesson: Layered stylesheets and component isolation.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Naming and component boundaries — knowledge check
Five questions on naming and component boundaries.
What does card__title conventionally represent?
What is card--featured typically used for?
Does a class naming convention enforce isolation?
Why use a narrow utility?
Which selector avoids affecting unrelated headings?