Blog PostSCSS Best Practices: Elevating OutSystems Themes

João Reis's picture

João Reis

/

Introduction

OutSystems is a powerful low-code platform that simplifies the creation, deployment, and management of web and mobile applications. While OutSystems excels in many areas, managing CSS directly within the platform can become challenging as themes grow in complexity. Developers often find it difficult to maintain a clean and organized codebase, track changes effectively, and ensure a consistent design throughout the application.

This is where SASS (Syntactically Awesome Style Sheets), a popular CSS preprocessor, comes into play. SCSS, a syntax of SASS, offers advanced features like variables, mixins, and nesting that enhance both the maintainability and scalability of your styles.

In this article, we explore best practices for incorporating SCSS into OutSystems, guiding you through essential techniques to elevate your application's visual appeal and ease of maintenance. From setting up your environment to applying methodologies like BEM, we provide a comprehensive roadmap for harnessing the full power of SCSS within OutSystems.


1. Team Organization

In SCSS projects, defining rules, including nomenclature and extensions, is crucial for efficient team organization. Consistent naming conventions enhance readability, while extensions work as tools to facilitate your work.

These guidelines promote smoother collaboration and contribute to successful project outcomes.

For example, establishing a consistent naming convention for classes can help team members quickly understand and modify code without confusion.

2. Organize your files

A well-structured SCSS project makes it easier to maintain and navigate, debug, and extend. Adopt a modular approach by organizing your styles into separate partial files, each dedicated to a specific purpose (e.g., variables, mixins, layouts, or components).

Import these partial files into a main SCSS file, which will be compiled into a single CSS file.

Files organization

In this structure

The main.scss file serves as the entry point, importing all the partial files from the respective folders. This file will be compiled into the final CSS file that you import into your OutSystems theme.

This modularity is especially useful in large projects, where adding new components or styles can be done seamlessly without affecting existing styles.


3. Integrating SCSS into Outsystems Themes

While OutSystems simplifies many aspects of application development, managing CSS directly within the platform can lead to challenges as themes grow in complexity. Developers often encounter issues with maintaining a clean and organized codebase, tracking changes, and ensuring consistent design across the application. SCSS addresses these challenges by providing a more structured and scalable approach to styling.

To integrate SCSS into your OutSystems projects effectively, follow these streamlined steps:

  1. Prepare Your Development Environment: Begin by installing Node.js and a SCSS compiler like Sass or node-sass.
  2. Structure Your SCSS Project: Organize your SCSS files into a clear folder hierarchy, including partial files and a main.scss file to manage your styles efficiently.
  3. Compile Your SCSS into CSS: Use your SCSS compiler to convert your SCSS files into a CSS file, executing the necessary terminal commands.
  4. Build a New Theme in OutSystems: Instead of altering the existing theme, create a new OutSystems theme that extends the original. Import the compiled CSS into this new theme, allowing you to enhance the design while preserving the ability to revert if necessary.
  5. Test and Deploy Your Theme: Use a local server (e.g., via VS Code) to compile and preview your SCSS in real-time. For testing, inject the compiled CSS into your OutSystems app using a Chrome plugin like Requestly. Once you're satisfied with the result, finalize by copying the CSS into OutSystems Studio.

By following these steps, you can improve the maintainability and visual appeal of your OutSystems applications, fully utilizing the capabilities of SCSS. Additionally, a project template is available on GitHub to help you start with best practices and a well-organized structure.


4. Maintainability? Use Variables

Make use of SCSS variables to store values such as colors, font sizes, and spacing units. This approach allows for easy modification of these values throughout the project, ensuring a consistent design.

OutSystems provides a set of built-in variables for colors, spacing, and other design elements, making it easier to maintain consistency and streamline the design process. These variables can be overridden or extended to meet the specific needs of your project. For example, in the case of the neutral color palette, we can redefine these values as shown below.

Additionally, if necessary, you can create new variables to accommodate custom design requirements. This flexibility ensures that your styles remain organized, maintainable, and adaptable to future changes.

No alternative text provided.
No alternative text provided.

5. Modular Design, Apply the BEM Methodology

Applying the BEM (Block, Element, Modifier) methodology in your SCSS can significantly improve the modularity and clarity of your code. BEM structures your CSS by breaking down components into blocks (e.g., a button), elements within those blocks (e.g., button text), and modifiers that define different states or versions of the component (e.g., a primary button).

By using BEM, you create a consistent naming convention that makes your styles easier to read, maintain, and extend. This approach is particularly beneficial in OutSystems projects, where maintaining a clean and scalable codebase is essential.

Find more about BEM


No alternative text provided.

6. Cleaner Code Through Nested Rules

SCSS enables you to nest selectors, which makes your code more organized and easier to read. However, avoid nesting too deeply to prevent over-specificity and difficulties in maintenance.

Keep nesting to a reasonable level—typically no more than three levels deep—to ensure your styles remain manageable and maintainable.


No alternative text provided.

7. Recycling, the Power of Mixins

Mixins are one of the most powerful features in SCSS, enabling you to create reusable blocks of styles that can be included in multiple selectors throughout your stylesheet. This approach not only ensures consistency across your designs but also adheres to the DRY (Don't Repeat Yourself) principle, reducing code duplication and making your styles easier to maintain.

By centralizing common styles into a mixin, you ensure that any changes are automatically reflected wherever the mixin is used.

example of using mixin

Conclusion

Enhance your OutSystems themes by implementing SCSS best practices, transforming your applications visually while ensuring easier maintenance and scalability. Organize your SCSS structure, utilize variables, mixins, and nested rules, and embrace methodologies like BEM for a consistent, modular design system. This investment in integrating SCSS into your OutSystems themes unlocks the full potential of both technologies, leading to user-friendly applications that are visually stunning and effortlessly managed. Start implementing these practices today to witness your OutSystems projects reach new heights in design and functionality.

In this guide, we've covered the basic steps to enhance your OutSystems themes with SCSS best practices. Best of luck with your development, and may your applications benefit greatly from the powerful capabilities of SCSS and OutSystems!