Transforming my CSS workflow with SASS: A web development journey

To provide some context for this article, I must first elaborate on some details. I am currently in the process of pursuing a career as a web developer, which I began just three months ago. Despite having no prior experience in programming or website development, I decided to embark on this journey because I felt strongly drawn to the field.

So, you might have already figured, that I ‘m not a senior code wizard yet, but my passion for programming is immense. After leaving my job in November 2022, I enrolled in an online course and have been fully immersed in the world of programming ever since. From the very first day, I have been deeply passionate about this field. Currently, I am taking my second online course alongside the first, and I am constantly working on various projects and ideas during my free time. It has been an exhilarating ride so far, as I discover with each new turn that the rabbit hole of programming goes on and on, and I eagerly absorb every bit of information I come across like a sponge.

After delving into my personal journey, I now turn my attention to why I fell in love with SASS. During one of my web development courses, I was assigned an assessment that allowed me to discuss any topic of my choice related to the field. Having recently discovered SASS in my programming exploration, I began using it and was immediately drawn to its appearance, particularly its nesting capabilities. Thus, I decided to center my course presentation around SASS, showcasing my newfound knowledge and sharing this amazing tool with my peers. I strongly believe that SASS lives up to its name and is truly awesome.

Advantages of using SASS:

SASS is a CSS precompiler (or preprocessor scripting language) that can seamlessly integrate with all versions of CSS, and it is available for free download with an engaged community and excellent documentation. Compared to traditional “vanilla” CSS, SASS offers remarkable benefits such as reducing code repetition, improving code readability, and simplifying the maintenance of stylesheets.

Moreover, SASS extends CSS with a range of features including inline comments, variables, mixins, functions, and much more that I have yet to explore. These capabilities not only make using SASS enjoyable, but also enhance my workflow and significantly improve the readability of my code.

Imagine you are working on a large-scale web development project that involves multiple developers and a complex set of design requirements. In this scenario, traditional CSS can quickly become unwieldy and difficult to manage, leading to a host of potential issues, including code repetition, inconsistent design elements, and difficulty in making global changes. This is where SASS (Syntactically Awesome Style Sheets) comes in. Since SASS extends the functionality of CSS providing a range of powerful features, it makes it easier to manage and organize your stylesheet code. One of the key benefits of SASS is the ability to use variables and mixins.

Variables:

Variables in SASS allow you to define a value once and reuse it throughout your stylesheet. For example, instead of hard-coding a color value like #00adb5 for each instance where it is used, you can define it once as a variable and use that variable in every instance. This makes it much easier to make global changes to the color scheme of your website or application, as you only need to change the value of the variable in one place.

//Variables in SCSS:

$background-color: #151515;
$font-color: #ffffff;
$highlight-color: #00adb5;
$border: 1px solid $highlight-color;
$border-radius: 20px;

Mixins:

Mixins are another powerful feature of SASS. A mixin is a group of CSS declarations that can be reused throughout your stylesheet, similar to a function in a programming language. For example, you might create a mixin for a specific layout element that includes multiple properties, such as padding, margins, and border styles. Once defined, you can use that mixin throughout your stylesheet, making it much easier to create consistent design elements across your entire site.

//Mixins in SCSS:

@mixin set-font(
$family: 'Poppins', 
$weight: 600, 
$style: normal, 
$transform: uppercase, 
$size: 4rem, 
$color: $font-color
){
font-family: $family, sans-serif;
font-weight: $weight;
font-style: $style;
text-transform: $transform;
font-size: $size;
color: $color;
}

@mixin set-border-layout(
$border: $border
){
border: $border;
border-radius: $border-radius;
}

@mixin set-layout(
$display: flex, 
$justify-content: center, 
$align-items: center, 
$width: 100%, 
$height: 100%
){
display: $display;
justify-content: $justify-content;
align-items: $align-items;
width: $width;
height: $height;
}

Nesting:

In addition to variables and mixins, SASS also allows for nested rules, which can help to organize and simplify your stylesheet code.SASS allows for nesting styles within other styles, resulting in more organized and readable code that is particularly useful for larger projects. Overall, SASS provides a powerful set of tools for managing and organizing your stylesheet code, making it an essential tool for modern web developers.

Code example:

The example code below shows the syntax of variables, mixins and the beauty of nesting of SASS, demonstrates some of the powerful features of SASS that can significantly improve your CSS workflow.

With variables and mixins, you can streamline your styling process and create cleaner, more maintainable code. The example code also demonstrates the benefits of nesting, which can help you organize your styles more intuitively.

//Code example:
.someDiv {
@include set-layout;
color: $font-color;
@include set-font;
@include set-border-layout;

ul {
margin: 1rem;
list-style-type: none;
   li {
      color: $fontColor;
    }
    span {
      color: $highlightColor;
      font-weight: 900;
    }
  }
}

If you’re new to SASS, now is the perfect time to start exploring its many features and capabilities. You’ll find that SASS can save you time and effort while also making your stylesheets more flexible and scalable. With a little bit of practice, you’ll be able to take your CSS skills to the next level and create stylesheets that are both elegant and efficient with SASS.

So why wait? Give SASS a try, discover some of the features not covered in this article and see for yourself how this powerful tool can transform your CSS workflow!