Skip to main content

PostCSS

PostCSS transforms extended syntaxes and features into modern, browser-friendly CSS. This guide will show you how to get started with Gatsby and PostCSS.

Installing and configuring PostCSS

This guide assumes that you have a Gatsby project set up. If you need to set up a project, head to the quick start guide, then come back.

  1. Install the Gatsby plugin gatsby-plugin-postcss.
  1. Include the plugin in your gatsby-config.js file.

Note: If you need to pass options to PostCSS use the plugins options; see postcss-loader for all available options.

  1. Write your stylesheets using PostCSS (.css files) and require or import them as normal.

With CSS modules

Using CSS modules requires no additional configuration. Simply prepend .module to the extension. For example: App.css -> App.module.css. Any file with the module extension will use CSS modules.

PostCSS plugins

If you would prefer to add additional postprocessing to your PostCSS output you can specify plugins in the plugin options:

Alternatively, you can use postcss.config.js to specify your particular PostCSS configuration:

Other resources


Edit this page on GitHub
Docs
Tutorials
Plugins
Blog
Showcase