By default, a site using Docsy has the theme’s default fonts, colors, and general look and feel. However, if you want your own color scheme (and you probably will!) you can very easily override the theme defaults with your own project-specific values - Hugo will look in your project files first when looking for information to build your site. And because Docsy uses Bootstrap 4 and SCSS for styling, you can override just single values (such as project colors and fonts) in its special SCSS project variables file, or do more serious customization by creating your own styles.
Docsy also provides options for styling your code blocks, using either Chroma or Prism for highlighting.
To customize your project’s look and feel, create your own version of either or both of the following
Docsy placeholder files (note the _project.scss
suffixes):
assets/scss/
_variables_project.scss
is where you add project-specific definitions of theme variables such as site colors, as well as any additional Bootstrap variable values you want to set. You can find a list of Docsy’s theme variables and their default values in assets/scss/_variables.scss
. For information about other Bootstrap 4 variables, see Variable defaults and Bootstrap’s v4-dev/scss/_variables.scss file.assets/scss/
_styles_project.scss
is where you can add your own custom SCSS styles, including overriding any of the styles in Docsy’s theme SCSS files.To easily customize your site’s colors, add SCSS variable overrides to
assets/scss/_variables_project.scss
. A simple example changing the primary and
secondary color to two shades of purple:
$primary: #390040;
$secondary: #A23B72;
The theme has features such as rounded corners and gradient backgrounds enabled by default. These can also be toggled in your project variables file:
$enable-gradients: true;
$enable-rounded: true;
$enable-shadows: true;
The theme uses Open Sans as its primary font. To disable Google Fonts and use a system font, set this SCSS variable in assets/scss/_variables_project.scss
:
$td-enable-google-fonts: false;
To configure another Google Font:
$google_font_name: "Open Sans";
$google_font_family: "Open+Sans:300,300i,400,400i,700,700i";
Note that if you decide to go with a font with different weights (in the built-in configuration this is 300
(light), 400
(medium) and 700
(bold)), you also need to adjust the weight related variables, i.e. variables starting with $font-weight-
.
For documentation of available CSS utility classes, see the Bootstrap Documentation. This theme adds very little on its own in this area. However, we have added some color state CSS classes that can be useful in a dynamic context:
.-bg-<color>
.-text-<color>
You can use these classes, for example, to style your text in an appropriate color when you don’t know if the primary
color is dark or light, to ensure proper color contrast. They are also useful when you receive the color code as a shortcode parameter.
The value of <color>
can be any of the color names, primary
, white
, dark
, warning
, light
, success
, 300
, blue
, orange
etc.
When you use .-bg-<color>
, the text colors will be adjusted to get proper contrast:
<div class="-bg-primary p-3 display-4">Background: Primary</div>
<div class="-bg-200 p-3 display-4">Background: Gray 200</div>
.-text-<color>
sets the text color only:
<div class="-text-blue pt-3 display-4">Text: Blue</div>
With Hugo version 0.60 and higher, you can choose from a range of code block highlight and colour styles using Chroma that are applied to your fenced code blocks by default. If you copied a recent config.toml
your site uses Tango (like this site), otherwise the Hugo default is Monokai. You can switch to any of the available Chroma styles (including our Docsy default Tango) using your config.toml
:
[markup]
[markup.goldmark]
[markup.goldmark.renderer]
unsafe = true
[markup.highlight]
# See a complete list of available styles at https://xyproto.github.io/splash/docs/all.html
style = "tango"
By default code highlighting styles are not applied to code blocks without a specified language, instead you get Docsy’s default style of grey with black text. If you would like the code highlighting style to apply to all code blocks, even without a language, uncomment or add the following line under [markup.highlight]
in your config.toml
.
# Uncomment if you want your chosen highlight style used for code blocks without a specified language
guessSyntax = "true"
You can find out more about code highlighting in Hugo with Chroma in Syntax Highlighting.
Optionally, you can enable Prism syntax highlighting in your config.toml
:
# Enable syntax highlighting and copy buttons on code blocks with Prism
prism_syntax_highlighting = true
When this option is enabled your site uses Prism instead of Chroma for code block highlighting.
Prism is a popular open source syntax highlighter which supports over 200 languages and various plugins.
Docsy includes JavaScript and CSS files for a basic Prism configuration, which supports:
Default
theme https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript+bash+c+csharp+cpp+go+java+markdown+python+scss+sql+toml+yaml&plugins=toolbar+copy-to-clipboard
By default Prism code highlighting styles are not applied to code blocks without a specified language, instead you get Docsy’s default style of grey with black text. To apply Prism styling to code blocks with no language or a language not supported by Prism, specify none
as the language after your triple backticks.
If the included Prism configuration is not sufficient for your requirements, and you want to use additional languages or plugins you can replace the included files with your own.
static/js/prism.js
static/css/prism.css
For pages containing a blocks/cover shortcode, like most homepages, the navbar is translucent as long as the hero image hasn’t scrolled up past the navbar. For an example, see the About Docsy page. This initial translucent setting ensures that the hero image is maximally visible.
After the hero image has scrolled past the navbar, the navbar’s (opaque) background color is set – usually to the site’s primary color.
The text of navbar entries can be difficult to read with some hero images. In
these cases, you can disable navbar translucency by setting the
params.ui.navbar_translucent_over_cover_disable
option to true
in your
site’s configuration file.
If you need to add some code (CSS import, cookie consent, or similar) to the head
section on every page, add the head-end.html
partial to your project:
layouts/partials/hooks/head-end.html
And add the code you need in that file. Your partial code is automatically included just before the end of the theme partial head.html
. The theme version of head-end.html
is empty.
Similarly, if you want to add some code right before the body
end, create your own version of the following file:
layouts/partials/hooks/body-end.html
Any code in this file is included automatically at the end of the theme partial scripts.html
.
Both head.html
and scripts.html
are then used to build Docsy’s base page layout, which is used by all the other page templates:
<!doctype html>
<html lang="{{ .Site.Language.Lang }}" class="no-js">
<head>
{{ partial "head.html" . }}
</head>
<body class="td-{{ .Kind }}">
<header>
{{ partial "navbar.html" . }}
</header>
<div class="container-fluid td-default td-outer">
<main role="main" class="td-main">
{{ block "main" . }}{{ end }}
</main>
{{ partial "footer.html" . }}
</div>
{{ partialCached "scripts.html" . }}
</body>
</html>
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.