diff --git a/material/partials/content.html b/material/partials/content.html
index ff9eedfa05dabcb3ae80e7a8aa11a396374bcef8..d756b647ee2cfbc29428c4a154ff49f75349949e 100644
--- a/material/partials/content.html
+++ b/material/partials/content.html
@@ -5,7 +5,8 @@
   {% include "partials/tags.html" %}
 {% endif %}
 {% include "partials/actions.html" %}
-{% if "\x3ch1" not in page.content %}
+{% set first = page.toc | first %}
+{% if first and first.level != 1 %}
   <h1>{{ page.title | d(config.site_name, true)}}</h1>
 {% endif %}
 {{ page.content }}
diff --git a/src/partials/content.html b/src/partials/content.html
index 6ec8b42d933fa5818535aef526a6950cdb39ca21..6930a1ed1076e74134a5c4bd977189e38072a256 100644
--- a/src/partials/content.html
+++ b/src/partials/content.html
@@ -29,10 +29,11 @@
 {% include "partials/actions.html" %}
 
 <!--
-  Hack: check whether the content contains a h1 headline. If it doesn't, the
+  Check whether the content starts with a level 1 headline. If it doesn't, the
   page title (or respectively site name) is used as the main headline.
 -->
-{% if "\x3ch1" not in page.content %}
+{% set first = page.toc | first %}
+{% if first and first.level != 1 %}
   <h1>{{ page.title | d(config.site_name, true)}}</h1>
 {% endif %}
 
diff --git a/src/partials/toc.html b/src/partials/toc.html
index de8c7b1464af2cd907b6ad15aebffcf1f36eb9c2..cb50b257b05e5f151116507e96f65c91caa3ff60 100644
--- a/src/partials/toc.html
+++ b/src/partials/toc.html
@@ -31,7 +31,7 @@
   {% set toc = page.toc %}
 
   <!--
-    Hack: check whether the content contains a h1 headline. If it does, the
+    Check whether the content starts with a level 1 headline. If it does, the
     top-level anchor must be skipped, since it would be redundant to the link
     to the current page that is located just above the anchor. Therefore we
     directly continue with the children of the anchor.