One of the difficult things in computer science and programming in general is naming things and naming things in CSS is no different even though some developers don't consider CSS as a real programming language but that's beginning to change with the addition of CSS variables.
When you work on a small sized project you might not give a priority to your selector names or how your project is structured but if by any chance the project becomes bigger than you expect then you will have to keep track of your selectors and using a naming convention can make this easy.
Naming conventions can be considered as an advanced concept in CSS therefore we'll briefly talk about them and I'll leave you to chose based on personal preferences and the size or structure of your project.
Contrary to the tradition of this series this post is more of theory than code.
There are two things that can come to mind when you open your CSS codebase (after a long period of time) or that of another developer:
WOW! this is cool
Oh My God who wrote this?
If you taught of the first option then you are in luck as the developer already did some heavy lifting and the code should be easy to maintain or modify. But, if its the second option you'll have lot of work on your hands and there should be an indication that you'll rename some selectors and following a naming convention will at least (to some extent) prevent another developer from going through a mental exercise of coming up with meaningful selector names.
The following are naming conventions that you can employ:
Thanks to a comment from @gracesnow, they made it clear that you are likely to encounter the BEM modifier being used with a double hyphen (--) in most places therefore, you can write the BEM modifier in the HTML as thus:
You should know that these states can be toggled with JavaScript as we'll demonstrate later in the series.
Theme rules
Theme rules are similar to state rules in that they describe how modules or layouts might look.
This is just an introduction to SMACSS. I'll encourage you to read the book online if you ever intend to use it.
ITCSS
ITCSS stands for Inverted Triangle CSS and its main philosophy is to help you organize your project CSS files in such a way that you can better deal the cascade, selectors and specificity.
ITCSS is partially proprietary meaning no official specification or documentation exists just a homepage stating its creator.
OOCSS
OOCSS means Object-Oriented CSS and its purpose is to encourage code reuse and ultimately stylesheets that are easier to maintain.
AMCSS is short for Attribute Module for CSS and the whole idea is about using HTML attributes and their values rather than classes for styling elements.
[am-Button]{/* code here */}[am-Button~="primary"]{/* code for primary button here */}
From a beginner's perspective I consider this advanced. But if you are curious you can visit the project page
Another naming convention is SUIT CSS naming conventions which relies on structured class names and meaningful hyphens. Again I consider this advanced, but you can visit the project page for more information.
UPDATE: 10th, December 2019
Additional resource (I consider it advanced for a beginner):
Viewing this from GitHub? Visit the website for the full experience. ricostacruz.com/rscss →
rscss
Styling CSS without losing your sanity
Reasonable System for CSS Stylesheet Structure.
A set of simple ideas to guide your process of building maintainable CSS.
Introduction
Any CSS greater than 1000 lines will get unwieldy. You'll eventually run into these common pitfalls:
"What does this class mean?"
"Is this class still being used?"
"If I make a new class green, will there be a clash?"
rscss is an attempt to make sense of all these. It is not a framework. It's simply a set of ideas to guide your process of building maintainable CSS for any modern website or application.
Let's get started by learning about components.
Continue →
According to the quick start guide on modifier:
Your example
--alert
is one of the Alternative naming schemes used in the BEM community know as Two Dashes style.You can check the examples in the naming convention section of the methodology.