Popular CSS methodologies

CSS coding conventions aim to serve as guidelines for writing CSS code and help to ensure consistency, maintainability, and scalability across a project. Here are some of the most commonly used:
BEM Methodology
The basic idea behind BEM is to create a clear and understandable naming structure for your CSS classes.
It separates your code into three distinct parts:
Block: Top-level container - ex: a header;
Element: Child element within the block - ex: logo within a header;
Modifier: A variation of a block or element - ex: a disabled button, a highlighted text, or a larger font size for a header.
The naming convention for BEM follows a specific pattern. It uses double underscores (__) to separate elements from blocks and double hyphens (--) to separate modifiers from blocks or elements:
/* BLOCK */
.block {}
/* ELEMENT */
.block__element {}
/* MODIFIER */
.block--modifier {}
Atomic design methodology
Atomic design breaks down a user interface into smaller, reusable components that can be combined to create more complex interfaces.
Atoms: The basic building blocks of a UI, such as buttons, inputs, and icon;
Molecules: Combinations of atoms that work together to perform specific functions, such as a search bar or a dropdown menu;
Organisms: Combinations of molecules and atoms that form a more complex component, such as a header, a footer, or a product card;
Templates: Complete layouts that combine multiple organisms and molecules to create a specific page or view;
Pages: Instances of a template that contain real content and represent a specific view or state of the application. Pages are the final stage of the design process and are the actual UI that users interact with.
/* ATOMS */
.search-input {}
.search-button {}
.search-icon {}
/* MOLECULES */
.search-form {}
/* ORGANISMS */
.search-bar {}
/* TEMPLATES */
.header {}
/* PAGES */
.search-results {}
SMACSS methodology
SMACSS (Scalable and Modular Architecture for CSS) was created by front-end developer Jonathan Snook, and it emphasizes the importance of consistency, maintainability, and scalability in CSS code.
The key principles of SMACSS are:
CSS rules are categorized into five types, based on their role in the page: Base, Layout, Module, State, and Theme.
Use a consistent naming convention for CSS classes, to make it easier to understand the purpose of each class and to avoid naming conflicts.
Avoid overly specific CSS selectors, as they can make it difficult to override styles and maintain consistency across the codebase.
Break down CSS into smaller, reusable components, which can be combined to create larger designs.
Separate the structure (HTML) from the skin (CSS), to make it easier to update the visual design of a site without affecting its underlying structure.
/* BASE */
.btn {}
/* LAYOUT */
.btn--primary {}
.btn--secondary {}
/* MODULE */
.btn__icon {}
.btn__text {}
/* STATE */
.btn.is-active {}
/* THEME */
.theme-dark .btn--primary {}
.theme-dark .btn--secondary {}
Ultimately, the best CSS methodology for a project will depend on factors like your team's preferences and experience, the size and complexity of your project, and your overall goals for the design and development process.
About the author
I am a front-end developer experienced working with React and Typescript.
So far I worked with product owners from multiple areas such as education, supply chain management, event planning, and product startups.
Before joining the front-end world, I worked as a data analyst, using Excel and Excel VBA as my daily drivers. I also had the opportunity to work as a network administrator where I learned how to build and configure Linux servers.
Comments
Join the discussionNo comments yet. Be the first to comment.





