Files
hugo/content/en/functions/css/Sass.md
T
Bjørn Erik Pedersen 8f3c066d23 Squashed 'docs/' changes from 1ad3c75ad..42914c50e
42914c50e content: Correct module mount example
d7b80be5f content: Add a "vendor" glossary entry
e1bd65866 content: Miscellaneous edits
deb1c4b1c content: Fix formatting
7ff740aae content: Update capitalizeListTitles documentation
a9f40164f content: Remove data namespace from functions
b3386a13a content: Remove expired content
e21f66fa5 content: Clean up deprecated service configurations
39ab42192 content: Change default value of respectDoNotTrack to true
067cbb771 Update partial-decorators.md
b419af329 content: Minor edits to collections functions
b12dd9366 content: Improve documentation for partial decorators
573b8610f content: Improve descriptions and signatures for collections functions
81befbae8 content: Update version references
684dbcedb Update HUGO_VERSION to 0.155.3
198e5f1df misc: Update README.md
4d20bbc04 content: Correct and improve glob patterns documentation
39d369ddc content: Update disablePathToLower documentation
be2da46e9 content: Miscellaneous edits to configuration documentation
19a580828 content: Add Commentix to the list of commercial commenting systems
d350725cd theme: Pin npm dependencies and adjust Netlify build commands
9b33bb5fa content: Define canonical output format and default site
84b72792e content: Document glob pattern matching logic
1839dd114 content: Create glob pattern quick reference
30f8f9ca0 content: Revise multi-dimensional content model description
b7e36e479 content: Fix formatting
b1722ac6b content: Indicate data types returned by the or function
1bbe3a566 content: Fix typo
b7e1ac7bb content: Improve example of _redirects rendering
37c71ef80 content: Improve and/or descriptions
0226c14ed content: Updates for v0.155.0
301fa208b content: Change GitHub Pages workflow to support dot files
5d07a679c Update HUGO_VERSION to 0.155.2
adb8e8b2c theme: Pin turbo
9206cb64b Update netlify.toml
84e712633 content: Refine ToMath admonition and provide example
a099af3cd content: Warn about conditional KaTeX CSS on list pages
c3ca7ac4c misc: Address build warnings
80a9139f4 Update HUGO_VERSION to 0.155.0
b096f6279 content: Restore homebrew on linux instructions
05132aa29 content: Hide snap installation instructions
d0e448a14 content: Refactor pages related to image processing
d141bc04f content: Clarify default site redirect description
1d6a0bed5 content: Adjust paragraph order
fa53534cb content: Clarify usage of quote characters in templates
1d62aa670 content: Miscellaneous edits
579c0678b content: Fix description of disableDefaultLanguageRedirect
cd12583ee Update all.md
37b01c320 Update HUGO_VERSION to 0.154.5
66053b6df content: Update version references
3f6fb8737 content: Refresh deployment dependencies to latest versions
c2915ee98 theme: Add a mobile menu variant
6457c3f59 Remove trailing whitespace from content/en/configuration/all.md
46c4d117a config: Mention disableDefaultDimensionRedirect
338500de0 Regen docs helper
98b9d25f3 Updates for 0.154.4 release
8306956e2 Update HUGO_VERSION to 0.154.4
af3f62992 Update HUGO_VERSION to 0.154.3
d06de65bd content: Fix typo
0d841a59e content: Fix typo
ed6fa87cf content: Fix typo
dcf80dbea content: Describe Markdown attribute access in render hook templates
70d3513f1 content: Update version references
7e581c529 Update netlify.toml
c6a706943 content: Remove expired pages
e64ee7d54 misc: Update workflows
bbec5a198 Update HUGO_VERSION to 0.154.1
e8717cb72 content: Fix formatting of glossary entry
0da233817 Add a link to templates.Inner from the partial decorator glossary entry
d55f7ad5e Update Inner.md
b674dfd48 Some more about templates.Inner
ef354e664 Remove some old new-in markers
7d1e407fd content: Misc updates for v0.154.0
43589a017 Update HUGO_VERSION to 0.154.0
46f832b9b content: Change shortcode usage note to an admonition
71ea41250 Adjust sponstors.toml
a5dc99838 Update netlify.toml
c3edd4d5b Update netlify.toml
c1d306d6b Add Zoomment to comments management options
cb222be99 Update HUGO_VERSION to 0.153.3
92ee87b4f content: Update CI/CD and version references
170bf3693 content: Note disabled extended check in v0.153.2 and later
34b5ef8b3 Update HUGO_VERSION to 0.153.2
c3c42b171 content: Add Dart Sass installation to SourceHut CI workflow
1768cc2f5 content: Fix links
63ba04562 theme: Modernize sans-serif font stack for cross-platform consistency
287da5c1c content: Update edition comparison and guidance
44b5010ca content: Update min version required for quick start
ec4f60cb7 content: Update version references
fafa69e7c Update HUGO_VERSION to 0.153.1
37bedd7d3 content: Fix formatting
ed9056088 content: Miscellaneous edits
fa4d61004 content: Miscellaneous post-release updates for v0.153.0
b99f47449 Misc v0.153.0 related edits
018c3e969 Regen docs.yml
be80ec4c7 content: Document new dimensions
ba397d5aa content: Miscellaneous updates for v0.153.0
59ca8fa3f Update HUGO_VERSION to 0.153.0

git-subtree-dir: docs
git-subtree-split: 42914c50ee338b00d0b1cda2c3af8066cd9ad65c
2026-02-14 12:13:44 +01:00

7.4 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

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.

Warning

The embedded LibSass transpiler was deprecated in v0.153.0 and will be removed in a future release. Use the Dart Sass transpiler instead.

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

Options

enableSourceMap
(bool) Whether to generate a source map. 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.
outputStyle
(string) The output style of the resulting CSS. With LibSass, one of nested (default), expanded, compact, or compressed. With Dart Sass, either expanded (default) or compressed.
precision
(int) The precision of floating point math. Applicable to LibSass. Default is 8.
silenceDeprecations
{{< new-in 0.139.0 />}}
(slice) A slice of deprecation IDs to silence. IDs are enclosed in brackets within Dart Sass warning messages (e.g., import in WARN Dart Sass: DEPRECATED [import]). Applicable to Dart Sass. Default is false.
silenceDependencyDeprecations
{{< new-in 0.146.0 />}}
(bool) Whether to silence deprecation warnings from dependencies, where a dependency is considered any file transitively imported through a load path. This does not apply to @warn or @debug rules.Default is false.
sourceMapIncludeSources
(bool) Whether to embed sources in the generated source map. Applicable to Dart Sass. Default is false.
targetPath
(string) The publish path for the transformed resource, relative to thepublishDir. If unset, the target path defaults to the asset's original path with a .css extension.
transpiler
(string) The transpiler to use, either libsass or dartsass. Hugo's extended and extended/deploy editions include the LibSass transpiler. To use the Dart Sass transpiler, see the installation instructions. Default is libsass.

Warning

The embedded LibSass transpiler was deprecated in v0.153.0 and will be removed in a future release. Use the Dart Sass transpiler instead.

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;

When passing a vars map to the css.Sass function, Hugo detects common typed CSS values such as 24px or #FF0000 using regular expression matching. If necessary, you can bypass automatic type inference by using the css.Quoted or css.Unquoted function to explicitly indicate a value's type.

Example

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

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. You must install the prebuilt binary outside of your project directory and ensure its path is included in your system's PATH environment variable.

Run hugo env to list the active transpilers.

Note

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.

Installing in a production environment

To use Dart Sass with Hugo on a CI/CD platform, you typically must modify your build workflow to install Dart Sass before the Hugo site build begins. This is because these platforms don't have Dart Sass pre-installed, and Hugo needs it to process your Sass files.

There's one key exception where you can skip this step: you have committed your resources directory to your repository. This is only possible if:

  • You have not changed Hugo's default asset cache location.
  • You have not set useResourceCacheWhen to never in your sites configuration.

By committing the resources directory, you're providing the pre-built CSS files directly to your CI/CD platform, so it doesn't need to run the Sass compilation itself.

For examples of how to install Dart Sass in a production environment, see these hosting guides:


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