diff --git a/python_docs_theme/layout.html b/python_docs_theme/layout.html
index b4502ba..82b7ef4 100644
--- a/python_docs_theme/layout.html
+++ b/python_docs_theme/layout.html
@@ -48,7 +48,7 @@
{{ _('Navigation') }}
{%- if builder != "htmlhelp" %}
@@ -76,6 +76,7 @@ {{ _('Navigation') }}
{%- if not embedded %}
+
{%- endif -%}
{%- endif -%}
diff --git a/python_docs_theme/static/search-focus.js b/python_docs_theme/static/search-focus.js
new file mode 100644
index 0000000..aa5b42f
--- /dev/null
+++ b/python_docs_theme/static/search-focus.js
@@ -0,0 +1,21 @@
+function isInputFocused() {
+ const activeElement = document.activeElement;
+ return (
+ activeElement.tagName === 'INPUT' ||
+ activeElement.tagName === 'TEXTAREA' ||
+ activeElement.isContentEditable
+ );
+}
+
+document.addEventListener('keydown', function(event) {
+ if (event.key === '/') {
+ if (!isInputFocused()) {
+ // Prevent "/" from being entered in the search box
+ event.preventDefault();
+
+ // Set the focus on the search box
+ const searchBox = document.getElementById('search-box');
+ searchBox.focus();
+ }
+ }
+});