diff --git a/sphinx/templates/genindex.html b/sphinx/templates/genindex.html
index 966c3f0c8..4096ddbc9 100644
--- a/sphinx/templates/genindex.html
+++ b/sphinx/templates/genindex.html
@@ -18,7 +18,7 @@
{%- set numcols = 1 %}
{%- set numitems = 0 %}
{% for entryname, (links, subitems) in entries %}
-
{%- if links -%}{{ entryname }}
+{%- if links -%}{{ entryname|e }}
{%- for link in links[1:] %}, [Link]{% endfor -%}
{%- else -%}
{{ entryname }}
@@ -26,7 +26,7 @@
{%- if subitems %}
{%- for subentryname, subentrylinks in subitems %}
- - {{ subentryname }}
+
- {{ subentryname|e }}
{%- for link in subentrylinks[1:] %}, [Link]{% endfor -%}
{%- endfor %}