HTML & CSSIntermediate

Learn Sass

Write more maintainable CSS with Sass - variables, nesting, and mixins.

3 hours
4 key concepts
2 in-depth sections
Official Docs

0 of 4 concepts completed (0%)

What You'll Learn

1.Variables, Nesting & Partials

scss
// _variables.scss design tokens
$color-primary:   #6200ee;
$color-secondary: #03dac6;
$color-error:     #b00020;
$spacing-base:    0.5rem;
$radius-md:       0.5rem;

// _buttons.scss using variables + nesting .btn { display: inline-flex; align-items: center; padding: $spacing-base * 2 $spacing-base * 4; border-radius: $radius-md; font-family: $font-body; cursor: pointer; transition: all 0.2s ease; border: none;

&-primary { background: $color-primary; color: white;

&:hover { background: darken($color-primary, 10%); } &:active { transform: scale(0.98); } &:disabled { opacity: 0.5; cursor: not-allowed; } }

&-outline { background: transparent; border: 2px solid $color-primary; color: $color-primary;

&:hover { background: $color-primary; color: white; } }

&--sm { padding: $spacing-base $spacing-base * 2; font-size: 0.875rem; } &--lg { padding: $spacing-base * 3 $spacing-base * 6; font-size: 1.125rem; } }

// main.scss @use 'variables' as *; @use 'buttons'; ```

2.Mixins & Functions

scss
// Responsive mixin
@mixin respond-to($breakpoint) {
  $map: (
    'sm':  640px,
    'md':  768px,
    'lg':  1024px,
    'xl':  1280px,
  );
  @media (min-width: map.get($map, $breakpoint)) { @content; }

// Flexbox helpers @mixin flex-center { display: flex; justify-content: center; align-items: center; }

@mixin flex-between { display: flex; justify-content: space-between; align-items: center; }

// Truncate text @mixin truncate($lines: 1) { @if $lines == 1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } @else { display: -webkit-box; -webkit-line-clamp: $lines; -webkit-box-orient: vertical; overflow: hidden; } }

// Usage .card { @include respond-to('md') { display: grid; }

&__title { @include truncate(2); font-size: 1.25rem; }

&__footer { @include flex-between; padding: 1rem; } }

// Sass function @function rem($px) { @return $px / 16px * 1rem; }

h1 { font-size: rem(40px); } // → 2.5rem ```

Code Example

// Sass variables
$primary-color: #3498db;
$spacing: 16px;

// Mixin
@mixin button-style {
  padding: $spacing;
  border-radius: 4px;
  border: none;
}

.button {
  @include button-style;
  background-color: $primary-color;
  color: white;
}

Pro Tips

  • 1Use the SCSS syntax (not the older indented syntax) it's a superset of CSS so any valid CSS is valid SCSS.
  • 2Keep your nesting to 3 levels maximum. Deeper nesting produces overly specific CSS that's hard to override and maintain.
  • 3@use replaces @import in modern Sass it scopes variables to the file and prevents global namespace pollution.
  • 4Sass maps are perfect for design tokens: $colors: ('primary': #6200ee, 'error': #b00020). Access with map.get($colors, 'primary').

Topics Covered

SassCSS PreprocessorVariables

Continue Learning

Explore the official documentation and deepen your knowledge with real-world practice.

Explore the Full Portfolio

This is the complete portfolio of Sufi Khan Sulaiman, a technology leader specialising in B2B commerce and digital automation. Start from the Home page for the overview, then move through two decades of career experience across FLIR Systems, Lorex Technology, and 1c Platform, and the full catalogue of project case studies spanning headless commerce migrations, AI recommendation engines, and multi-channel fulfilment systems.

The skills and certifications page maps the technical and leadership capabilities behind the work, while the articles and the knowledge base break down the thinking into actionable frameworks. For hands-on learning, the tutorials and applications sections cover practical builds from front-end fundamentals to full-stack web apps.

For consulting engagement, the expertise page outlines service offerings, the ecommerce hub covers platform architecture and automation strategy, and the ecommerce guide (PDF) is a downloadable 55-page field manual. When you are ready to talk, the contact page is the direct line.