Files
hugo/content/en/functions/css/Sass.md
T
Bjørn Erik Pedersen 5be51ac3db Squashed 'docs/' changes from d1a251933..dc7a9ae12
dc7a9ae12 content: Update JS options
07d3d8803 npm: Use tilde ranges for versions
e06362a13 Minor grammar fixes
c42db0838 content: Algolia DocSearch clarification
d67412b82 deps: Upgrade to TailwindCSS 4.1.0
da1fb12d3 theme: Update Lato font path for images.Text example
140fa3bb9 Update introduction.md
7b1fcca27 content: Fix links to embedded template source
908a55532 theme: Improve dark mode syntax highlighting background
d830e5962 Update XxHash.md
807be5dbf Update Defer.md
4b56693f6 content: Update GitHub Pages sample workflow
57b766fba Update TailwindCSS.md
64982ab6a Update TailwindCSS.md
1b6e879c6 Update TailwindCSS.md
e67cbcdd2 content: Add caching to the GitHub Pages workflow example
b7ca3b07c Update index.md
14e1a3977 Update XxHash.md
980f344ae Update XxHash.md
6b815f03e theme: Remove aria-label attribute from links
1c00bbc45 theme: Update npm dependencies
533149bf9 theme: Include section pages in related content
2b6bda6bd content: Fix typos
92ce95cbb content: Miscellaneous edits
f12936681 theme: Add a simple LRU cache for search
339ca3388 Fix the previous broken commit
8537e59e0 Make it into a non-link
e13f17d29 Add Algolia logo/link to the search listing dialog
d3e09e886 content: Fix typo
7217f64b6 content: Miscellaneous edits
51aa1ae73 content: Improve some examples
8ebaa53f9 theme: Adjust shortcodes
898870438 theme: Hide anchor until mouse-over
c933ea237 content: More front matter cleanup
f26ca047a content: Miscellaneous edits
e272b2039 theme: Fix inline partial refs
c540e6d29 content: Replace note shortcode calls with blockquote alerts
aef899bc5 theme: Add title and QR code when printing
bd46ef626 theme: Implement blockquote render hook
ddefbefaa content: Improve contributing page
f41d28ee1 content: Adjust usage of whitespace removal with action delimiters
03315336d theme: Use full title in related content sidebar
4f4076364 misc: Document the front matter fields used on this site
2f78d7632 misc: Fix gitignore file
7de6dbab3 content: Fix front matter for several function pages
5d3542ea6 config: Disable tags taxonomy
68bc28d67 content: Add linkTitle to shortcode pages
5f32c92ed theme: Restore deduplication logic for related items
a943a4bb8 theme: Implement related content tooling
fd628be6e content: Replace calls to the code shortcode with fenced code blocks
b23c9a583 content: Fix position of new-in badges
ec056f251 content: Fix typo
245351c84 theme: Adjust spacing in highlighting theme examples
2fcd21ee5 content: Remove "related" array from function and method pages
71d8426ee theme: Create code block render hook
4cdde6649 theme: Adjust number of news items to display
34ab45261 content: Miscellaneous edits
b6cae5cbc content: Consolidate configuration documentation
727ef6f66 theme: Fix overflow issue for wide tables
c4f759e01 Add es2024
93cce62c8 Update support list of more recent targets with js.Build / esbuild
974d0655f Update hosting-on-codeberg.md
b3f0ed9ce content: Add hosting instructions for Codeberg Pages
8217c0900 content: Correct the SourceHut repository URL
a8cf3d28f content: Add hosting instructions for SourceHut Pages
8c059cbe1 theme: Use content adapter for news section
03938c600 Remove some old new-in
5c50a75e8 content: Fix typo
5cf89f2f6 theme: Re-enable banner gtag outbound link tracking
3c555d5f8 One more copy button
94bce999a Add some copy buttons
9e1cc0c2b Update PortableText.md
dd26ac49f Document transform.PortableText
5f632ab32 netlify: Hugo 0.145.0
59e057bb4 Update index.md
d07e07d6c Remove some unused home page front matter
d482657b7 Add footnote about alias to the build front matter key
f0629b77c content: Fix typo
d91c4cccf theme: Fix news items URLs
ca931cd1f theme: Restore RSS feed for news section
e6b870bc9 theme: Adjust copy-to-clipboard button
071851431 Update netlify.toml
e68431034 theme: Format layouts
aa3cd839a theme: Format assets
22ad3eee3 theme: Add some more space on the right for copy buttons
f4a19083a netlify: Hugo 0.144.1
974cb8795 theme: Remove Internet Explorer configs (#2929)
4a23a1f41 content: Fix typos
d49f15d03 theme: Get the scrollspy back working
720c7ff67 config: Evict getresource cache hourly
1f62ca97e theme: Hide the Turbo progress bar
f6449ace3 Move the dark class up to the html element
074cd1a07 content: Miscellaneous edits
e098a7716 content: Miscellaneous edits
8e1e104aa content: Updates for v0.144.0
18e1aa916 theme: Add anchor links via JS
ac3b5505c Close new-in
bfa4db6b8 netlify: Hugo 0.144.0
fd6e7feee Regen CLI docs
da9d1218a Regen docs helper
5de494ded Merge branch 'tempv0.144.0'
f683e6469 theme: Minor improvements to base template
ef8bf89d8 resources/page: Revise the new contentbasename permalinks tokens
901adb07b resources/page: Add :contentbasename and :contentbasenameorslug permalink tokens
0fca8ef25 all: Change shortcode usage and design to prevent invalid HTML
c41d76613 Update RegularPagesRecursive.md
e93574748 content: Correct return type for strings.Split
3d504abba Revert "content: Add ids to the Netlify steps"
c08c8e15e content: Add ids to the Netlify steps
5a3b470a2 theme: "move" the id from content to article
b878613aa theme: Add page kind as a CSS class to body
269657e8f content: Fix formatting error
664f6c92f config: Change image cache location
fa6b719b1 theme: Reduce ToC to level 2-4
bc16341ca theme: Render mathematical markup with transform.ToMath
14bf9dc70 theme: Add aria-label attribute to search fields
ed42af5b3 theme: Adjust search field and search activation
f042e4970 dev: Add prettier-plugin-void-html
f6ec83533 content: Fix inline shortcode example
0a74210e2 theme: Remove readfile shortcode
334ca06ac theme: Fix some dark mode accessibility as reported by Axe core
02626ff92 theme: aria-lbabel => aria-label
227b76ab7 Add Prettier and config
43ab22428 content: Bump minimum required Go version to 1.23.0
03e54683f modules: Add GOAUTH to module config
9f06a3b9c js/esbuild: Add drop option
ddcd99369 Merge commit 'a024bc7d76fcc5e49e8210f9b0896db9ef21861a'
733731253 helpers: Add Chroma styles to docs.yaml

git-subtree-dir: docs
git-subtree-split: dc7a9ae127
2025-04-10 13:02:49 +02:00

8.5 KiB

title, description, categories, keywords, params
title description categories keywords params
css.Sass Transpiles Sass to CSS.
functions_and_methods
aliases returnType signatures
toCSS
resource.Resource
css.Sass [OPTIONS] RESOURCE

{{< new-in 0.128.0 />}}

{{ with resources.Get "sass/main.scss" }}
  {{ $opts := dict
    "enableSourceMap" (not hugo.IsProduction)
    "outputStyle" (cond hugo.IsProduction "compressed" "expanded")
    "targetPath" "css/main.css"
    "transpiler" "libsass"
  }}
  {{ with . | toCSS $opts }}
    {{ if hugo.IsProduction }}
      {{ with . | fingerprint }}
        <link rel="stylesheet" href="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous">
      {{ end }}
    {{ else }}
      <link rel="stylesheet" href="{{ .RelPermalink }}">
    {{ end }}
  {{ end }}
{{ end }}

Transpile Sass to CSS using the LibSass transpiler included in Hugo's extended and extended/deploy editions, or install Dart Sass to use the latest features of the Sass language.

Sass has two forms of syntax: SCSS and indented. Hugo supports both.

Options

transpiler
(string) The transpiler to use, either libsass (default) or dartsass. Hugo's extended and extended/deploy editions include the LibSass transpiler. To use the Dart Sass transpiler, see the installation instructions below.
targetPath
(string) If not set, the transformed resource's target path will be the original path of the asset file with its extension replaced by .css.
vars
(map) A map of key-value pairs that will be available in the hugo:vars namespace. Useful for initializing Sass variables from Hugo templates.
// LibSass
@import "hugo:vars";

// Dart Sass
@use "hugo:vars" as v;
outputStyle
(string) Output styles available to LibSass include nested (default), expanded, compact, and compressed. Output styles available to Dart Sass include expanded (default) and compressed.
precision
(int) Precision of floating point math. Not applicable to Dart Sass.
enableSourceMap
(bool) Whether to generate a source map. Default is false.
sourceMapIncludeSources
(bool) Whether to embed sources in the generated source map. Not applicable to LibSass. Default is false.
includePaths
(slice) A slice of paths, relative to the project root, that the transpiler will use when resolving @use and @import statements.
{{ $opts := dict
  "transpiler" "dartsass"
  "targetPath" "css/style.css"
  "vars" site.Params.styles
  "enableSourceMap" (not hugo.IsProduction)
  "includePaths" (slice "node_modules/bootstrap/scss")
}}
{{ with resources.Get "sass/main.scss" | toCSS $opts | minify | fingerprint }}
  <link rel="stylesheet" href="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous">
{{ end }}
silenceDeprecations
(slice) {{< new-in 0.139.0 />}} A slice of deprecation IDs to silence. The deprecation IDs are printed to in the warning message, e.g "import" in WARN Dart Sass: DEPRECATED [import] .... This is for Dart Sass only.

Dart Sass

Hugo's extended and extended/deploy editions include LibSass to transpile Sass to CSS. In 2020, the Sass team deprecated LibSass in favor of Dart Sass.

Use the latest features of the Sass language by installing Dart Sass in your development and production environments.

Installation overview

Dart Sass is compatible with Hugo v0.114.0 and later.

If you have been using Embedded Dart Sass1 with Hugo v0.113.0 and earlier, uninstall Embedded Dart Sass, then install Dart Sass. If you have installed both, Hugo will use Dart Sass.

If you install Hugo as a Snap package there is no need to install Dart Sass. The Hugo Snap package includes Dart Sass.

Installing in a development environment

When you install Dart Sass somewhere in your PATH, Hugo will find it.

OS Package manager Site Installation
Linux Homebrew brew.sh brew install sass/sass/sass
Linux Snap snapcraft.io sudo snap install dart-sass
macOS Homebrew brew.sh brew install sass/sass/sass
Windows Chocolatey chocolatey.org choco install sass
Windows Scoop scoop.sh scoop install sass

You may also install prebuilt binaries for Linux, macOS, and Windows.

Run hugo env to list the active transpilers.

Installing in a production environment

For CI/CD deployments (e.g., GitHub Pages, GitLab Pages, Netlify, etc.) you must edit the workflow to install Dart Sass before Hugo builds the site2 . Some providers allow you to use one of the package managers above, or you can download and extract one of the prebuilt binaries.

GitHub Pages

To install Dart Sass for your builds on GitHub Pages, add this step to the GitHub Pages workflow file:

- name: Install Dart Sass
  run: sudo snap install dart-sass

If you are using GitHub Pages for the first time with your repository, GitHub provides a starter workflow for Hugo that includes Dart Sass. This is the simplest way to get started.

GitLab Pages

To install Dart Sass for your builds on GitLab Pages, the .gitlab-ci.yml file should look something like this:

variables:
  HUGO_VERSION: 0.144.2
  DART_SASS_VERSION: 1.85.0
  GIT_DEPTH: 0
  GIT_STRATEGY: clone
  GIT_SUBMODULE_STRATEGY: recursive
  TZ: America/Los_Angeles
image:
  name: golang:1.20-buster
pages:
  script:
    # Install Dart Sass
    - curl -LJO https://github.com/sass/dart-sass/releases/download/${DART_SASS_VERSION}/dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz
    - tar -xf dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz
    - cp -r dart-sass/* /usr/local/bin
    - rm -rf dart-sass*
    # Install Hugo
    - curl -LJO https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb
    - apt install -y ./hugo_extended_${HUGO_VERSION}_linux-amd64.deb
    - rm hugo_extended_${HUGO_VERSION}_linux-amd64.deb
    # Build
    - hugo --gc --minify
  artifacts:
    paths:
      - public
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

Netlify

To install Dart Sass for your builds on Netlify, the netlify.toml file should look something like this:

[build.environment]
HUGO_VERSION = "0.144.2"
DART_SASS_VERSION = "1.85.0"
NODE_VERSION = "22"
TZ = "America/Los_Angeles"

[build]
publish = "public"
command = """\
  curl -LJO https://github.com/sass/dart-sass/releases/download/${DART_SASS_VERSION}/dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz && \
  tar -xf dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz && \
  rm dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz && \
  export PATH=/opt/build/repo/dart-sass:$PATH && \
  hugo --gc --minify \
  """

Example

To transpile with Dart Sass, set transpiler to dartsass in the options map passed to css.Sass. For example:

{{ with resources.Get "sass/main.scss" }}
  {{ $opts := dict
    "enableSourceMap" (not hugo.IsProduction)
    "outputStyle" (cond hugo.IsProduction "compressed" "expanded")
    "targetPath" "css/main.css"
    "transpiler" "dartsass"
  }}
  {{ with . | toCSS $opts }}
    {{ if hugo.IsProduction }}
      {{ with . | fingerprint }}
        <link rel="stylesheet" href="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous">
      {{ end }}
    {{ else }}
      <link rel="stylesheet" href="{{ .RelPermalink }}">
    {{ end }}
  {{ end }}
{{ end }}

Miscellaneous

If you build Hugo from source and run mage test -v, the test will fail if you install Dart Sass as a Snap package. This is due to the Snap package's strict confinement model.


  1. In 2023, the Sass team deprecated Embedded Dart Sass in favor of Dart Sass. ↩︎

  2. You do not have to do this if (a) you have not modified the assets cache location, and (b) you have not set useResourceCacheWhen to never in your site configuration, and (c) you add and commit your resources directory to your repository. ↩︎