Add custom JavaScript

Add JavaScript files or add code inline by extending the templates.

Add JavaScript files

To add extra JavaScript files, add your code to a file—for example, _static/custom.js and add the following options to your Sphinx configuration:

pythonFile: conf.py
html_static_path = ["_static"]
html_js_files = ["custom.js"]

Extend templates with inline JavaScript

If you want to add JavaScript inline, or load additional external scripts, you can extend the default page template and override the extrahead block:

html+jinjaFile: page.html
{% extends "!page.html" %}

{{ super() }}

{% block extrahead %}
<script>
 // Add your JavaScript code here
</script>
{% endblock %}