A CSS class is a name assigned through an HTML element’s class attribute. CSS uses that name to group elements and target them with selectors, making styles easier to organize and maintain. Clear names based on an element’s content or purpose are easier to understand than names based only on appearance. section 8.6
Opening a share menu
A share component can begin with a hidden menu styled by .share__menu. When the Share button is clicked, JavaScript toggles the share_expanded class on the container. The selector .share_expanded .share__menu then gives the menu a width of 200px and adds horizontal padding, revealing the links. The modifier name describes the component’s open state rather than a permanent visual feature. section 11.6.2 section 11.6.2
Use CSS classes to:
- Group related elements under a shared style. section 8.6
- Represent a temporary state, such as an expanded component. section 11.6.2
- Follow a naming convention such as BEM, where share_expanded combines the share block with an expanded modifier. section 11.6.2
Compare the closed and expanded component states to see how adding a class changes the menu’s presentation. section 11.6.2




