Sphinx Bootstrap Theme
Sphinx Bootstrap Theme integrates the Bootstrap CSS/JavaScript framework with Sphinx documentation, offering various layout options, hierarchical menu navigation, and mobile-friendly responsive design. It is configurable, extensible, and supports different Bootswatch CSS themes. The current version is 0.8.1. Releases occur irregularly, indicating active but not rapid development.
Common errors
-
Bootstrap theme isn't loading javascript parts / Navbar isn't working correctly
cause Often due to conflicts with existing jQuery or other JavaScript, or incorrect loading of theme's JS/CSS assets.fixEnsure `html_theme_path` and `html_theme = 'bootstrap'` are correctly set in `conf.py`. Check browser console for JavaScript errors. Ensure no conflicting jQuery versions are loaded or that your custom JS uses `$jqTheme` for theme-related interactions. -
Sidebar T.O.C isn't working / Table of contents not showing
cause Incorrect configuration of `html_sidebars` or issues with the theme's JavaScript responsible for rendering the table of contents.fixVerify that `html_sidebars` is configured to include the global or local table of contents (e.g., `['localtoc.html', 'relations.html', 'sourcelink.html', 'searchbox.html']`). Check theme options related to TOC depth. If using a custom `globaltoc.html`, ensure it's correct. -
Theme not applying / Build errors after changing theme
cause New themes can sometimes conflict with existing Sphinx configuration options, particularly `html_sidebars`, `html_theme_path`, or `html_theme_config`.fixTemporarily comment out or unset `html_sidebars`, `html_theme_path`, or `html_theme_config` in your `conf.py` and rebuild. If the build succeeds, reintroduce options one by one to identify the conflict.
Warnings
- gotcha The theme supports Bootstrap v2.3.2 and v3.3.7. Bootstrap 3 has known limitations such as dropped support for sub-menus in the navigation. Ensure you set `bootstrap_version` in `html_theme_options` to your desired version (default is '3').
- gotcha The theme integrates its own jQuery (as `$jqTheme`) using `noConflict()` to avoid clashes with Sphinx's internal jQuery. Custom JavaScript that directly relies on `$` for jQuery might encounter conflicts or unexpected behavior.
- breaking Upgrading Bootstrap versions (even within the theme) can break custom CSS or JavaScript that relies on specific Bootstrap class names or HTML structures, as these frequently change between major Bootstrap versions.
- gotcha If `navbar_title` is not explicitly set in `html_theme_options`, the theme defaults to using the `project` variable from `conf.py`. This often includes version numbers which might not be desirable for a clean navigation bar title.
Install
-
pip install sphinx-bootstrap-theme
Imports
- sphinx_bootstrap_theme
import sphinx_bootstrap_theme
- html_theme
html_theme = 'bootstrap'
- html_theme_path
html_theme_path = sphinx_bootstrap_theme.get_html_theme_path()
Quickstart
# conf.py
import os
import sys
import sphinx_bootstrap_theme
project = 'My Project'
copyright = '2026, My Team'
author = 'My Team'
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.napoleon'
]
html_theme = 'bootstrap'
html_theme_path = sphinx_bootstrap_theme.get_html_theme_path()
html_theme_options = {
'bootstrap_version': '3', # Can be '2' or '3'
'navbar_sidebarrel': False, # Remove 'prev' and 'next' links from navbar
'navbar_links': [
("Home", "index"),
("About", "about"),
("GitHub", "https://github.com/your-org/your-project", True)
],
'bootswatch_theme': "flatly", # Example: "flatly", "journal", etc.
'navbar_title': "My Project Docs"
}