0
0
SASSmarkup~5 mins

SASS with PostCSS pipeline

Choose your learning style9 modes available
Introduction

SASS helps write CSS faster and cleaner. PostCSS can add extra features like fixing browser differences automatically.

You want to use variables and nesting in your CSS for easier styling.
You need to add browser prefixes automatically for better compatibility.
You want to optimize your CSS by minifying or adding future CSS features.
You want a smooth way to write modern CSS that works everywhere.
You want to combine multiple CSS tools in one process.
Syntax
SASS
sass input.scss | postcss --use autoprefixer -o output.css
You first write styles in a .scss file using SASS syntax.
Then you run PostCSS with plugins like autoprefixer to process the CSS.
Examples
This SASS code uses a variable and nesting.
SASS
// input.scss
$main-color: #06c;

body {
  color: $main-color;
  nav {
    background: lighten($main-color, 20%);
  }
}
This command runs PostCSS with autoprefixer to add browser prefixes.
SASS
postcss input.css --use autoprefixer -o output.css
Run SASS first to convert SCSS to CSS, then PostCSS to enhance CSS.
SASS
sass input.scss output.css
postcss output.css --use autoprefixer -o final.css
Sample Program

This example shows a simple webpage styled with SASS variables and nesting. PostCSS adds browser prefixes automatically to the CSS for better support.

SASS
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>SASS with PostCSS Example</title>
  <link rel="stylesheet" href="final.css" />
</head>
<body>
  <nav>Menu</nav>
  <p>Hello, styled with SASS and PostCSS!</p>
</body>
</html>

/* input.scss */
$main-color: #3498db;

body {
  font-family: Arial, sans-serif;
  color: $main-color;
  nav {
    background-color: lighten($main-color, 15%);
    padding: 1rem;
    border-radius: 0.5rem;
  }
}

/* After running:
   sass input.scss output.css
   postcss output.css --use autoprefixer -o final.css
*/
OutputSuccess
Important Notes

Always write SASS first, then run PostCSS to process the CSS output.

PostCSS plugins like autoprefixer help fix browser differences automatically.

Use a build tool or script to automate running SASS and PostCSS together.

Summary

SASS lets you write CSS with variables and nesting for easier styles.

PostCSS processes CSS to add features like browser prefixes automatically.

Use them together by compiling SASS first, then running PostCSS on the result.