About this articleThis article was created using an automated generation workflow powered by generative AI. Marked 17.0.5 Markdown conversion and HTML output precautions were verified against official documentation, and the included code was cross-referenced with the material implementation.
Verification Status: 🧪 Marked conversion and static code review completed / GitHub Pages rendering and browser interaction unverifiedWe verified the initial inputs and outputs with modified heading symbols using Marked 17.0.5 in a Node.js 24.22.3 environment. Live rendering on published pages, browsers, and Mermaid diagrams has not been confirmed.
See how Markdown headings map to HTML | marked
Markdown headings represent hierarchy based on the number of # symbols at the beginning of a line. However, it can be slightly confusing at first to understand what HTML is generated when symbols are changed, and whether the visual appearance matches the HTML structure.
This material uses Marked, a JavaScript library that converts Markdown to HTML. Change the # in the input field to ## or ###, and compare the resulting <h1>、<h2>、<h3> in the output field. This is intended for editors of CMS or procedure manuals, and beginners learning HTML heading structures.
Live demo comparing outputs by changing heading symbols
Static material README and implementation files
Change inputs and compare HTML
Open the live demo and click "Run". The initial value is
# 見出しand bullet points- 手順.In the result field,
<h1>見出し</h1>and the list representation<ul>・<li>appear as text.# 見出しto## 見出しand re-run. The resulting<h1>changes to<h2>.Changing the same line to
### 見出しresults in<h3>. If necessary, try up to###### 見出し.
| Markdown input | Heading HTML returned by Marked | What to observe |
|---|---|---|
# 見出し | <h1>見出し</h1> | Level 1 heading |
## 見出し | <h2>見出し</h2> | Adding one leading symbol changes the level |
### 見出し | <h3>見出し</h3> | The same change continues |
# 見出し\n\n- 手順 | <h1>…</h1> and list item | Convert headings and bullet lists into separate HTML elements |
What we are looking at in this experiment is the output HTML string. In the result section, tags are not rendered as large headings, but can be read in the form of <h1>. Since on-screen font sizes and margins can also be changed via CSS, you cannot determine the HTML heading level based on appearance alone.
# selects document structure rather than appearance
In CommonMark's ATX heading syntax, 1 to 6 # characters at the beginning of a line represent the heading level. For example, ## 準備 is level 2. When converted to HTML, it becomes <h2>準備</h2>. While there is also a format that involves writing a closing # at the end, this tutorial focuses on the basic syntax.ATX headings in the CommonMark specification include rules on the number of symbols and whitespace conditions, along with conversion examples.
h1〜h6 represents the heading hierarchy within a page. Do not choose headings merely as decoration to make text look larger; instead, determine the level by considering "what section this subsection belongs to." For example, if the page's main topic is h1, the major chapter underneath it is h2, and the subheading within that chapter is h3, in that order. Font size is handled by CSS, while structure is handled by heading elements.
The code converts Markdown into an HTML string
The demo implementation takes the input string, passes it to Marked's parse(), and displays the result in the results section.
const { marked } = await lib("marked@17.0.5");
say(await marked.parse(value));
lib() is the common loader for this demo. It loads Marked 17.0.5 from a local file in the learning materials.marked.parse(value) converts Markdown into an HTML string, and say() displays the string in the results pane. In this implementation, because say() uses textContent, HTML tags are displayed as literal strings rather than being interpreted by the browser.
The initial value # 見出し is converted to <h1>見出し</h1>, and - 手順 is converted to <ul><li>手順</li></ul>. If you add another # to the input, the output heading tag also changes from h1 to h2.
Marked's output is not inherently safe HTML
This is a common point of misjudgment in professional development. While Marked generates HTML from Markdown, it does not sanitize that HTML to ensure safety. If the input contains raw HTML, it may persist in the conversion result. Render conversion results as strings, as shown in the learning materials, and never insert unvalidated input directly as page HTML.
Because this demo displays results using textContent, output tags are not executed and can be read as characters. However, in an actual preview, if you assign directly to innerHTML like this, the browser will treat the input content as HTML.
preview.innerHTML = await marked.parse(userMarkdown);
If your design involves rendering user input as HTML, follow the official Marked guidelines by processing the output HTML with a sanitizer such as DOMPurify before safely inserting it. In addition to sanitizing before display, verify permitted HTML elements and attributes, link handling, and update methods. The learning materials use fictitious input containing only headings; do not paste actual internal company documents or personal information.
Applying Heading Usage to Your Work
Checking heading levels ensures that chapter and section relationships are preserved even after Markdown-authored instruction manuals or FAQs are converted to HTML. When migrating manuscripts to a CMS, if the article's table of contents is arranged in an unnatural order, or if it is difficult to navigate the list of headings using a screen reader, verify not only the visual appearance but also the tag hierarchy.
However, the mere correct output of HTML tags does not prove the correctness of the entire article structure. Verify the section order, heading wording, correspondence with the body text, and the Markdown dialect of the CMS being used in conjunction. Because extended syntax and HTML handling differ across GitHub and various CMS platforms, moving to a different converter does not guarantee the same results.
When things do not work
| Observation | Points to check |
|---|---|
| The result is empty or displays "Could not execute" | Check for JavaScript errors in the browser console and verify whether the page has successfully loaded daily.js and vendor/marked.mjs |
<h1> is displayed as a large heading | Check whether the output destination is textContent or innerHTML. This tutorial displays tag strings. |
| Only Mermaid diagrams fail to display | Because diagram rendering uses an external CDN, check for network restrictions or loading errors. Diagram contents can also be verified via the description and source. |
#見出し is not as expected | #Check the number of # 見出し and the trailing whitespace. First, insert a half-width space after symbols like |
While the core Marked module is loaded as a fixed version from within the tutorial, rendering Mermaid diagrams requires external CDN communication. Diagrams may not render in network-restricted environments. Even if diagrams are not visible, the heading conversion experiments and HTML string verification are separate features.
Official documentation and licenses
Marked 17.0.5 README – APIs and considerations for sanitizing generated HTML
Marked 17.0.5 LICENSE – MIT License
CommonMark 0.31.2 ATX Heading Specification – Heading syntax and examples of conversion to HTML
Mermaid Syntax Reference – Flowchart syntax for the tutorial
Summary
The number of # at the beginning of a line determines the HTML hierarchy rather than the heading size. By comparing the output of #、##、### in the demo, you can verify how the concise Markdown notation is converted into h1、h2、h3.
When using Marked in production, treat HTML conversion and HTML safety as separate concerns. While this tutorial displays tags as plain strings, ensure that proper sanitization is included in your design when rendering user-submitted Markdown as HTML in a preview interface.
Verification Method
We verified execution on Node.js 24.22.3 and Marked 17.0.5, confirming the initial input, the conversion results for heading levels 1 to 3, and cases where raw HTML within Markdown remains in the output. The implementation HTML, initial input, button names, loaders in the common script, say(), and README were read back and verified against each other. GitHub Pages display, actual browser operations, Mermaid rendering, and external CDN communication have not been verified.
