Debian Codegraph @

doc/usage/theming.rst

raw
1 .. highlight:: python
2
3 .. _html-themes:
4
5 HTML theming
6 ============
7
8 Sphinx provides a number of builders for HTML and HTML-based formats.
9
10 Builders
11 --------
12
13 .. todo:: Populate when the 'builders' document is split up.
14
15
16 Themes
17 ------
18
19 .. versionadded:: 0.6
20
21 .. note::
22
23 This section provides information about using pre-existing HTML themes. If
24 you wish to create your own theme, refer to
25 :ref:`extension-html-theme`.
26
27 Sphinx supports changing the appearance of its HTML output via *themes*. A
28 theme is a collection of HTML templates, stylesheet(s) and other static files.
29 Additionally, it has a configuration file which specifies from which theme to
30 inherit, which highlighting style to use, and what options exist for customizing
31 the theme's look and feel.
32
33 Themes are meant to be project-unaware, so they can be used for different
34 projects without change.
35
36 Using a theme
37 ~~~~~~~~~~~~~
38
39 Using a :ref:`theme provided with Sphinx <builtin-themes>` is easy. Since these
40 do not need to be installed, you only need to set the :confval:`html_theme`
41 config value. For example, to enable the ``classic`` theme, add the following
42 to :file:`conf.py`::
43
44 html_theme = "classic"
45
46 You can also set theme-specific options using the :confval:`html_theme_options`
47 config value. These options are generally used to change the look and feel of
48 the theme. For example, to place the sidebar on the right side and a black
49 background for the relation bar (the bar with the navigation links at the
50 page's top and bottom), add the following :file:`conf.py`::
51
52 html_theme_options = {
53 "rightsidebar": "true",
54 "relbarbgcolor": "black"
55 }
56
57 If the theme does not come with Sphinx, it can be in two static forms or as a
58 Python package. For the static forms, either a directory (containing
59 :file:`theme.toml` and other needed files), or a zip file with the same
60 contents is supported. The directory or zipfile must be put where Sphinx can
61 find it; for this there is the config value :confval:`html_theme_path`. This
62 can be a list of directories, relative to the directory containing
63 :file:`conf.py`, that can contain theme directories or zip files. For example,
64 if you have a theme in the file :file:`blue.zip`, you can put it right in the
65 directory containing :file:`conf.py` and use this configuration::
66
67 html_theme = "blue"
68 html_theme_path = ["."]
69
70 The third form is a Python package. If a theme you want to use is distributed
71 as a Python package, you can use it after installing
72
73 .. code-block:: console
74
75 # installing theme package
76 $ pip install sphinxjp.themes.dotted
77
78 Once installed, this can be used in the same manner as a directory or
79 zipfile-based theme::
80
81 html_theme = "dotted"
82
83 For more information on the design of themes, including information about
84 writing your own themes, refer to :ref:`extension-html-theme`.
85
86 .. _builtin-themes:
87
88 Builtin themes
89 ~~~~~~~~~~~~~~
90
91 .. cssclass:: longtable, standard
92
93 +--------------------+--------------------+
94 | **Theme overview** | |
95 +--------------------+--------------------+
96 | |alabaster| | |classic| |
97 | | |
98 | *alabaster* | *classic* |
99 +--------------------+--------------------+
100 | |sphinxdoc| | |scrolls| |
101 | | |
102 | *sphinxdoc* | *scrolls* |
103 +--------------------+--------------------+
104 | |agogo| | |traditional| |
105 | | |
106 | *agogo* | *traditional* |
107 +--------------------+--------------------+
108 | |nature| | |haiku| |
109 | | |
110 | *nature* | *haiku* |
111 +--------------------+--------------------+
112 | |pyramid| | |bizstyle| |
113 | | |
114 | *pyramid* | *bizstyle* |
115 +--------------------+--------------------+
116
117 .. |alabaster| image:: /_static/themes/alabaster.png
118 .. |classic| image:: /_static/themes/classic.png
119 .. |sphinxdoc| image:: /_static/themes/sphinxdoc.png
120 .. |scrolls| image:: /_static/themes/scrolls.png
121 .. |agogo| image:: /_static/themes/agogo.png
122 .. |traditional| image:: /_static/themes/traditional.png
123 .. |nature| image:: /_static/themes/nature.png
124 .. |haiku| image:: /_static/themes/haiku.png
125 .. |pyramid| image:: /_static/themes/pyramid.png
126 .. |bizstyle| image:: /_static/themes/bizstyle.png
127
128 Sphinx comes with a selection of themes to choose from.
129
130 Note that from these themes only the Alabaster and Scrolls themes are
131 mobile-optimated, the other themes resort to horizontal scrolling
132 if the screen is too narrow.
133
134 .. cssclass:: clear
135
136 These themes are:
137
138 **basic**
139 This is a basically unstyled layout used as the base for the
140 other themes, and usable as the base for custom themes as well. The HTML
141 contains all important elements like sidebar and relation bar. There are
142 these options (which are inherited by the other themes):
143
144 - **nosidebar** (true or false): Don't include the sidebar. Defaults to
145 ``False``.
146
147 - **sidebarwidth** (int or str): Width of the sidebar in pixels.
148 This can be an int, which is interpreted as pixels or a valid CSS
149 dimension string such as '70em' or '50%'. Defaults to 230 pixels.
150
151 - **body_min_width** (int or str): Minimal width of the document body.
152 This can be an int, which is interpreted as pixels or a valid CSS
153 dimension string such as '70em' or '50%'. Use 0 if you don't want
154 a width limit. Defaults may depend on the theme (often 450px).
155
156 - **body_max_width** (int or str): Maximal width of the document body.
157 This can be an int, which is interpreted as pixels or a valid CSS
158 dimension string such as '70em' or '50%'. Use 'none' if you don't
159 want a width limit. Defaults may depend on the theme (often 800px).
160
161 - **navigation_with_keys** (true or false): Allow navigating
162 with the following keyboard shortcuts:
163
164 - :kbd:`Left arrow`: previous page
165 - :kbd:`Right arrow`: next page
166
167 Defaults to ``False``.
168
169 - **enable_search_shortcuts** (true or false): Allow jumping to the search box
170 with :kbd:`/` and allow removal of search highlighting with :kbd:`Esc`.
171
172 Defaults to ``True``.
173
174 - **globaltoc_collapse** (true or false): Only expand subsections
175 of the current document in ``globaltoc.html``
176 (see :confval:`html_sidebars`).
177 Defaults to ``True``.
178
179 .. versionadded:: 3.1
180
181 - **globaltoc_includehidden** (true or false): Show even those
182 subsections in ``globaltoc.html`` (see :confval:`html_sidebars`)
183 which have been included with the ``:hidden:`` flag of the
184 :rst:dir:`toctree` directive.
185 Defaults to ``False``.
186
187 .. versionadded:: 3.1
188
189 - **globaltoc_maxdepth** (int): The maximum depth of the toctree in
190 ``globaltoc.html`` (see :confval:`html_sidebars`). Set it to -1 to allow
191 unlimited depth. Defaults to the max depth selected in the toctree directive.
192
193 .. versionadded:: 3.2
194
195 **alabaster**
196 `Alabaster theme`_ is a modified "Kr" Sphinx theme from @kennethreitz
197 (especially as used in his Requests project), which was itself originally
198 based on @mitsuhiko's theme used for Flask & related projects. Refer to its
199 `installation page`_ for information on how to configure
200 :confval:`html_sidebars` for its use.
201
202 .. _Alabaster theme: https://pypi.org/project/alabaster/
203 .. _installation page: https://alabaster.readthedocs.io/en/latest/installation.html
204
205 **classic**
206 This is the classic theme, which looks like `the Python 2
207 documentation <https://docs.python.org/2/>`_. It can be customized via
208 these options:
209
210 - **rightsidebar** (true or false): Put the sidebar on the right side.
211 Defaults to ``False``.
212
213 - **stickysidebar** (true or false): Make the sidebar "fixed" so that it
214 doesn't scroll out of view for long body content. This may not work well
215 with all browsers. Defaults to ``False``.
216
217 - **collapsiblesidebar** (true or false): Add an *experimental* JavaScript
218 snippet that makes the sidebar collapsible via a button on its side.
219 Defaults to ``False``.
220
221 - **externalrefs** (true or false): Display external links differently from
222 internal links. Defaults to ``False``.
223
224 There are also various color and font options that can change the color scheme
225 without having to write a custom stylesheet:
226
227 - **footerbgcolor** (CSS color): Background color for the footer line.
228 - **footertextcolor** (CSS color): Text color for the footer line.
229 - **sidebarbgcolor** (CSS color): Background color for the sidebar.
230 - **sidebarbtncolor** (CSS color): Background color for the sidebar collapse
231 button (used when *collapsiblesidebar* is ``True``).
232 - **sidebartextcolor** (CSS color): Text color for the sidebar.
233 - **sidebarlinkcolor** (CSS color): Link color for the sidebar.
234 - **relbarbgcolor** (CSS color): Background color for the relation bar.
235 - **relbartextcolor** (CSS color): Text color for the relation bar.
236 - **relbarlinkcolor** (CSS color): Link color for the relation bar.
237 - **bgcolor** (CSS color): Body background color.
238 - **textcolor** (CSS color): Body text color.
239 - **linkcolor** (CSS color): Body link color.
240 - **visitedlinkcolor** (CSS color): Body color for visited links.
241 - **headbgcolor** (CSS color): Background color for headings.
242 - **headtextcolor** (CSS color): Text color for headings.
243 - **headlinkcolor** (CSS color): Link color for headings.
244 - **codebgcolor** (CSS color): Background color for code blocks.
245 - **codetextcolor** (CSS color): Default text color for code blocks, if not
246 set differently by the highlighting style.
247
248 - **bodyfont** (CSS font-family): Font for normal text.
249 - **headfont** (CSS font-family): Font for headings.
250
251 **sphinxdoc**
252 The theme originally used by this documentation. It features
253 a sidebar on the right side. There are currently no options beyond
254 *nosidebar* and *sidebarwidth*.
255
256 .. note::
257
258 The Sphinx documentation now uses
259 `an adjusted version of the sphinxdoc theme
260 <https://github.com/sphinx-doc/sphinx/tree/master/doc/_themes/sphinx13>`_.
261
262 **scrolls**
263 A more lightweight theme, based on `the Jinja documentation
264 <https://jinja.palletsprojects.com/>`_. The following color options are
265 available:
266
267 - **headerbordercolor**
268 - **subheadlinecolor**
269 - **linkcolor**
270 - **visitedlinkcolor**
271 - **admonitioncolor**
272
273 **agogo**
274 A theme created by Andi Albrecht. The following options are supported:
275
276 - **bodyfont** (CSS font family): Font for normal text.
277 - **headerfont** (CSS font family): Font for headings.
278 - **pagewidth** (CSS length): Width of the page content, default 70em.
279 - **documentwidth** (CSS length): Width of the document (without sidebar),
280 default 50em.
281 - **sidebarwidth** (CSS length): Width of the sidebar, default 20em.
282 - **rightsidebar** (true or false): Put the sidebar on the right side.
283 Defaults to ``True``.
284 - **bgcolor** (CSS color): Background color.
285 - **headerbg** (CSS value for "background"): background for the header area,
286 default a grayish gradient.
287 - **footerbg** (CSS value for "background"): background for the footer area,
288 default a light gray gradient.
289 - **linkcolor** (CSS color): Body link color.
290 - **headercolor1**, **headercolor2** (CSS color): colors for <h1> and <h2>
291 headings.
292 - **headerlinkcolor** (CSS color): Color for the backreference link in
293 headings.
294 - **textalign** (CSS *text-align* value): Text alignment for the body, default
295 is ``justify``.
296
297 **nature**
298 A greenish theme. There are currently no options beyond
299 *nosidebar* and *sidebarwidth*.
300
301 **pyramid**
302 A theme from the Pyramid web framework project, designed by Blaise Laflamme.
303 There are currently no options beyond *nosidebar* and *sidebarwidth*.
304
305 **haiku**
306 A theme without sidebar inspired by the `Haiku OS user guide
307 <https://www.haiku-os.org/docs/userguide/en/contents.html>`_. The following
308 options are supported:
309
310 - **full_logo** (true or false, default ``False``): If this is true, the
311 header will only show the :confval:`html_logo`. Use this for large logos.
312 If this is false, the logo (if present) will be shown floating right, and
313 the documentation title will be put in the header.
314
315 - **textcolor**, **headingcolor**, **linkcolor**, **visitedlinkcolor**,
316 **hoverlinkcolor** (CSS colors): Colors for various body elements.
317
318 **traditional**
319 A theme resembling the old Python documentation. There are
320 currently no options beyond *nosidebar* and *sidebarwidth*.
321
322 **epub**
323 A theme for the epub builder. This theme tries to save visual
324 space which is a sparse resource on ebook readers. The following options
325 are supported:
326
327 - **relbar1** (true or false, default ``True``): If this is true, the
328 ``relbar1`` block is inserted in the epub output, otherwise it is omitted.
329
330 - **footer** (true or false, default ``True``): If this is true, the
331 ``footer`` block is inserted in the epub output, otherwise it is omitted.
332
333 **bizstyle**
334 A simple bluish theme. The following options are supported
335 beyond *nosidebar* and *sidebarwidth*:
336
337 - **rightsidebar** (true or false): Put the sidebar on the right side.
338 Defaults to ``False``.
339
340 .. versionadded:: 1.3
341 'alabaster', 'sphinx_rtd_theme' and 'bizstyle' theme.
342
343 .. versionchanged:: 1.3
344 The 'default' theme has been renamed to 'classic'. 'default' is still
345 available, however it will emit a notice that it is an alias for the new
346 'alabaster' theme.
347
348 .. _third-party-themes:
349
350 Third Party Themes
351 ~~~~~~~~~~~~~~~~~~
352
353 There are many third-party themes created for Sphinx. Some of these are for
354 general use, while others are specific to an individual project.
355
356 sphinx-themes.org__ is a gallery that showcases various themes for Sphinx,
357 with demo documentation rendered under each theme. Themes can also be found
358 on PyPI__ (using the classifier ``Framework :: Sphinx :: Theme``), GitHub__
359 and GitLab__.
360
361 .. __: https://sphinx-themes.org/
362 .. __: https://pypi.org/search/?q=&o=&c=Framework+%3A%3A+Sphinx+%3A%3A+Theme
363 .. __: https://github.com/search?utf8=%E2%9C%93&q=sphinx+theme
364 .. __: https://gitlab.com/explore?name=sphinx+theme