On this page

Arrange the page

The theme draws a header, a primary sidebar, the page, a secondary sidebar and a footer. A site chooses where they sit, and what each one holds, with theme options.

Set the layout

  1. Set layout in html_theme_options in conf.py:

    html_theme_options = {
        "layout": "lHh LpR lff",
    }
    
  2. Build the site. A code that is not a layout code stops the build with a message saying what a code needs.

The primary sidebar now reaches the top-left corner. The layout code describes each letter.

Fill a component list

  1. Choose the list for where the component goes, from Options.

  2. Name the components, in the order they should appear:

    html_theme_options = {
        "footer_start": ["copyright", "last-updated"],
        "footer_end": ["sphinx-version", "theme-version"],
    }
    
  3. Set html_last_updated_fmt, so that last-updated has a date to show:

    html_last_updated_fmt = "%d %B %Y"
    

The footer now shows the components in that order. A component whose Sphinx setting is off draws nothing. Components names the setting for each one.

Add your own component

  1. Add a directory for your templates to templates_path in conf.py, if the site has none:

    templates_path = ["_templates"]
    
  2. Write the template as _templates/status.html:

    <p>Status: stable</p>
    
  3. Name it in a list:

    html_theme_options = {
        "footer_center": ["status"],
    }
    

The footer now shows the template. A name that matches no template draws nothing and raises no warning, so a misspelt name leaves a gap and no message.

Moving between pages

Each page ends with links to the previous and the next page in the table of contents. To turn them off, set show_prev_next to False.

To let readers move with the left and right arrow keys, set navigation_with_keys to True:

html_theme_options = {
    "navigation_with_keys": True,
}

A button that scrolls back to the top appears while the reader scrolls up, far down a page. Set back_to_top_button to False to remove it. All three options are described in Options.

Put an announcement across every page

Set announcement to the text of a banner that appears at the top of every page:

html_theme_options = {
    "announcement": "Version 2 is out. <a href='/changes.html'>See what changed</a>",
}

The text may hold HTML of your own, and the theme prints it as written. To keep the banner in one file, set announcement to an address that starts with http:// or https://. The page script fetches that address when a reader opens a page and puts the HTML it returns in the banner. The banner is removed when the address fails, cannot be reached or returns nothing.

To keep the banner in view with the header, set sticky_banners to True:

html_theme_options = {
    "sticky_banners": True,
}

Both options are described in Options.

How the page behaves for a reader

The browser changes the page as the window changes:

  • Below 64rem wide, the primary sidebar becomes a drawer. A button in the header opens it, and a link in it, the close button, a press outside it or the Escape key closes it.

  • From 80rem wide, the secondary sidebar appears beside the page.

  • An area marked with an upper-case letter in the layout code stays in view while the page scrolls, and the sticky areas sit below the header, whatever height it has.

  • Below 40rem wide, the items in navbar_end move into the drawer.

  • A skip link is the first thing a keyboard reader reaches, and it jumps to the page.

The search and index pages leave out the secondary sidebar, as they have no headings of their own.