Can I shift second-level headings up one level to display as third-level ones in the HTML output?

Hello,
I’ve been using the Emacs Org format until now, and when I specified two asterisks for a headline (to create a level-two heading), it appeared as H3 in HTML. Three asterisks would produce H4, and so on.

Today, I decided to experiment a bit with Markdown, and in Markdown, two asterisks result in H2, which is logical. However, I would like each heading in Markdown to be increased by one level in HTML. For example, ## to be H3 in HTML, and ### to be H4 in the HTML output. Can this be set somewhere?

Thank you.

You can create a heading render hook. Something like:

{{- $level := math.Min (add .Level 1) 6 -}}
<h{{ $level }} id="{{ .Anchor }}">
  {{- .Text -}}
</h{{ $level }}>

In English, the name of the Unicode # character is “number sign”.
https://www.compart.com/en/unicode/U+0023

1 Like

I reworked the above. I forgot we had min/max.

Thank you. I have the title of the website as H1, and as far as I know, it’s not good to have multiple H1s on a single page. H2 is for section titles like “Blog Posts,” which is why I thought it’s better to start with H3 when it comes to the content. That way, it follows the order.

I guess it’s just a matter of preference.

My preference is to not use an h1 element for the site title. Then each page title is h1, and the top level Markdown section is h2.

+++
title = 'Post 1'
+++

## Section 1

### Section 1.1

### Section 1.2

## Section 2

Thank you. I’ll do the same. It’s definitely a better idea. I noticed that you use a logo. On my site, it’s just simple text, so I think H1 is the most suitable. I’ll go with two H1s, and I’ll give the site title a separate ID so I can set a different size than the blog post titles. Thank you so much. I appreciate your time.

There’s some SEO guidance indicating that h1 elements should only be used for page title, but there’s a lot of SEO guidance out there that is… questionable.

1 Like

I found a more recent article, from what I can see it was published this month, where Google confirms that it’s okay. Multiple H1 Tags on Page is Perfectly Fine in SEO - Stan Ventures

1 Like

There are also conflicting opinions about whether multiple h1 elements on a page hurt accessibility.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.