6 - Styling
  • choices for styling
  • sass + css modules
  • typographyjs

Styling


Before we move forward, let me mention that my site now may look slightly different from yours from now on. Because I’ve removed all the starter content and replaced with my own. Furthermore, I’ve stripped off nearly all existing CSS so that I will use my own. You don’t have to do that right now. Instead, I’ll tell you what to add or remove along the way.

Because layout is also a React component, you can style it with (or without) any styling framework you prefer. This means you may use pure CSS, Sass, CSS-in-JS, styled components, etc.

Ask for each framework’s familiarity.

Add Sass



$ yarn add sass gatsby-plugin-sass

// in gatsby-config.js
plugins: [
  {
    resolve: `gatsby-plugin-sass`,
    options: {
      implementation: require("sass"),
    },
  },
]



Today, we’ll use Sass with CSS Modules.

(Ask) Has anybody used CSS modules before?

  • CSS Modules is a build step (with the help of Webpack or Browserify) that changes class names and selectors to be scoped. 

One reason to use CSS modules with Gatsby is that the scoped class names work very well with the component-based mindset, which is a default with React.

You may learn more using CSS Modules with Gatsby by reading the CSS Modules section in Gatsby’s official tutorial.

Using SASS + CSS Modules with Gatsby


To use Sass + CSS Modules with Gatsby, we need to name our stylesheet to end with module.scss. Let’s go ahead rename the current index.css to s.module.scss for our layout.

// src/layout/s.module.scss

// ...other styles