The first thing you'll want to do is import some settings by using one of these import statements:

import scalacss.Defaults._     // Choose dev or prod
import scalacss.DevDefaults._  // Always use dev settings
import scalacss.ProdDefaults._ // Always use prod settings

This provides two sets of sensible settings: development and production.

Property Dev Prod
Style conflicts Keep both sides of conflict.
Issue warnings.
Keep both sides of conflict.
Error handling Print to stderr Ignore
Class name generation .<class>-<val>
Eg. .MyStyles-outer
CSS output Pretty-print.
Indents, spaces, newlines.
No whitespace.

Defaults will choose a mode to use based on its devMode: Boolean method which uses elision to determine production-mode.

For instance, in my production SBT settings I generally have:

// Prod settings
scalacOptions ++= Seq("-Xelide-below", "OFF")

Note: -Xelide-below OFF doesn't turn eliding off, it means "elide everything". There must've been painting going on in the building with no windows open when that was named.

Defaults aren't mandatory, you're free to customise as needed. (See DefaultSettings.scala.)


Styles, attributes, values, nearly everything in ScalaCSS is immutable. When you're declaring a large module of styles, it's very inconvenient to have to manually collate all styles you declare. mutable.StyleSheet exists for this purpose. Subclass it, create your styles and they will be registered automatically so that you can turn them all into CSS at once.

Stylesheets come in two different flavours: standalone and inline.

Property Standalone Inline
Purpose Generating a CSS file. Styling in a Scala or Scala.JS webapp.
CSS Selectors
(class names)
You need to specify.
Generated when not provided.
Usable style types Static only: StyleS All types: StyleS, StyleF, StyleC.
Return type after creation Unit StyleA (A = Applicable)
Declaration style "" - ... val box = style(...)

To create a style module,

  1. Create an object that extends StyleSheet.Standalone or StyleSheet.Inline.
  2. Inside the object, import the DSL by typing import dsl._.
  3. Following the examples, just start typing and if you're using an IDE with auto-complete, you'll be guided towards type-safe styles.
Full examples: