| title | Customizing Hextra |
|---|---|
| linkTitle | Customization |
Hextra offers some default customization options in the hugo.yaml config file to configure the theme.
This page describes the available options and how to customize the theme further.
To add custom CSS, we need to create a file assets/css/custom.css in our site. Hextra will automatically load this file.
The font family of the content can be customized using:
.content {
font-family: "Times New Roman", Times, serif;
}The color of text mixed with other text can customized with:
.content code:not(.code-block code) {
color: #c97c2e;
}The primary color of the theme can be customized by setting the --primary-hue, --primary-saturation and --primary-lightness variables:
:root {
--primary-hue: 100deg;
--primary-saturation: 90%;
--primary-lightness: 50%;
}Hextra provides CSS variables to customize the width of pages, navbar, and footer:
:root {
/* Page width - also configurable via hugo.yaml params.page.width */
--hextra-max-page-width: 80rem; /* default: 80rem (normal), 90rem (wide), 100% (full) */
/* Navbar width - also configurable via hugo.yaml params.navbar.width */
--hextra-max-navbar-width: 90rem; /* independent navbar width */
/* Footer width - also configurable via hugo.yaml params.footer.width */
--hextra-max-footer-width: 80rem; /* independent footer width */
}Starting with Hextra v0.10.0, which is built on Tailwind CSS v4, you can customize the theme by overriding CSS variables inside the @layer theme block.
This lets you customize the global look and feel without having to modify every individual class.
@layer theme {
:root {
--hx-default-mono-font-family: "JetBrains Mono", monospace;
}
}Check out Tailwind Theme Variables documentation for details.
The theme can be further customized by overriding the default styles via the exposed css classes. An example for customizing the footer element:
.hextra-footer {
/* Styles will be applied to the footer element */
}
.hextra-footer:is(html[class~="dark"] *) {
/* Styles will be applied to the footer element in dark mode */
}The following classes can be used to customize various parts of the theme.
hextra-scrollbar- The scrollbar elementcontent- Page content container
hextra-badge- The badge element
hextra-card- The card elementhextra-card-image- The card image elementhextra-card-icon- The card icon elementhextra-card-subtitle- The card subtitle element
hextra-cards- The cards grid container
hextra-jupyter-code-cell- The Jupyter code cell containerhextra-jupyter-code-cell-outputs-container- The Jupyter code cell outputs containerhextra-jupyter-code-cell-outputs- The Jupyter code cell output div element
hextra-pdf- The PDF container element
hextra-steps- The steps container
hextra-tabs-panel- The tabs panel containerhextra-tabs-toggle- The tabs toggle button
hextra-filetree- The filetree container
hextra-filetree-folder- The filetree folder container
hextra-nav-container- The navbar containerhextra-nav-container-blur- The navbar container in blur elementhextra-hamburger-menu- The hamburger menu button
hextra-footer- The footer elementhextra-custom-footer- The custom footer section container
hextra-search-wrapper- The search wrapper containerhextra-search-input- The search input elementhextra-search-results- The search results list container
Optional nested classes used within the search UI:
hextra-search-title- The result title elementhextra-search-active- The active result anchorhextra-search-no-result- The empty state elementhextra-search-prefix- The breadcrumb/prefix label for grouped resultshextra-search-excerpt- The result snippet texthextra-search-match- The highlighted query span
hextra-toc- The table of contents container
hextra-sidebar-container- The sidebar containerhextra-sidebar-active-item- The active item in the sidebar
hextra-language-switcher- The language switcher buttonhextra-language-options- The language options container
hextra-theme-toggle- The theme toggle button
hextra-code-copy-btn-container- The code copy button containerhextra-code-copy-btn- The code copy buttonhextra-copy-icon- The copy icon elementhextra-success-icon- The success icon element
hextra-code-block- The code block containerhextra-code-filename- The filename element for code blocks
hextra-feature-card- The feature card link element
hextra-feature-grid- The feature grid container
List of available syntax highlighting themes are available at Chroma Styles Gallery. The stylesheet can be generated using the command:
hugo gen chromastyles --style=githubTo override the default syntax highlighting theme, we can add the generated styles to the custom CSS file.
You may add custom scripts to the end of the head for every page by adding the following file:
layouts/_partials/custom/head-end.html
You can add extra section in the footer by creating a file layouts/_partials/custom/footer.html in your site.
<!-- Your footer element here -->The added section will be added before the copyright section in the footer. You can use HTML and Hugo template syntax to add your own content.
Hugo variables available in the footer section are: .switchesVisible and .displayCopyright.
The layouts of the theme can be overridden by creating a file with the same name in the layouts directory of your site.
For example, to override the single.html layout for docs, create a file layouts/docs/single.html in your site.
For further information, refer to the Hugo Templates.
Didn't find what you were looking for? Feel free to open a discussion or make a contribution to the theme!