Embed generated CSS in HTML

I’m using SCSS and having HUGO generate the CSS which works fine and I can set up a link to the generated stylesheet, no problem. However, I’d like to embed the contents of that CSS file into the HTML and I can’t find a way of doing that. Is it possible?

https://gohugo.io/methods/resource/content/

Search the page for “To create inline CSS”

Perhaps by using .Content instead of .Permalink. Without seeing your code, difficult to say.

Thanks for your quick replies

I tried this

{{- $opts := dict "transpiler" "libsass" "targetPath" "css/style.css" "outputStyle" "compressed" }}
{{- with resources.Get "/scss/critical.scss" | toCSS $opts }}
{{- end -}}

{{ with resources.Get "css/style.css" }}
  <style>{{ .Content | safeCSS }}</style>
{{ end }}

but no style tag is generated so there’s something I’m not understanding here!

{{- with resources.Get "/scss/critical.scss" | toCSS $opts }}
  <style>{{ .Content | safeCSS }}</style>
{{- end -}}
2 Likes

That’s it. Thank you.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.