Skip to content

Guide · Open source

How to use markdown-it: install and render Markdown in JavaScript

Updated · written with AI from the project's own documentation and checked against our catalogue data

markdown-it is a Markdown parser for JavaScript and TypeScript projects. It converts Markdown text into HTML and follows the CommonMark standard. This guide shows you how to install it with npm, render a string of Markdown, and where to look for plugins and further options.

markdown-itmarkdown-it/markdown-it · ★ 22k · MIT

Quick start

  1. 1Check Node.js. Make sure Node.js is installed, since the README lists it as the prerequisite for npm installation.
  2. 2Install the package. Run npm install markdown-it in your project folder.
  3. 3Import the library. Add import MarkdownIt from 'markdown-it' to your script.
  4. 4Create an instance. Call new MarkdownIt() to make a parser with default settings.
  5. 5Render your text. Pass a Markdown string to md.render() and use the returned HTML.
  6. 6Explore plugins. Search npm for markdown-it plugins if you need extra syntax.

What markdown-it does

markdown-it is a library, not an app. You give it Markdown text and it returns HTML that you can place on a web page or use inside a Node.js or browser project.

It follows the CommonMark spec for how Markdown should be read. It also adds extras such as URL autolinking and a typographer option.

  • Follows the CommonMark spec and adds syntax extensions such as URL autolinking and typographer.
  • Configurable: you can add new rules and replace existing ones.
  • Safe by default, according to the README.
  • Community plugins and other packages are available on npm.

Install markdown-it with npm

The README lists Node.js as the prerequisite and shows installation through npm. Run this command in your project folder:

npm install markdown-it

Render Markdown to HTML

Import the library, create an instance, and call render with your Markdown string. The method returns the HTML as a string.

import MarkdownIt from 'markdown-it' const md = new MarkdownIt() const result = md.render('# markdown-it rulezz!')

Use markdown-it in the browser

The README says that for browsers you can use a CDN that mirrors the npm registry, such as unpkg.com, esm.sh, or another CDN. You can look at the contents of the dist/ folder at unpkg.com/markdown-it/ to see what is available.

Extend markdown-it with plugins and custom rules

You can add new parsing rules or replace existing ones. Community-written plugins are published on npm, and the README links to a keyword search for markdown-it plugins.

For more examples and the full API, read the documentation and the usage examples linked from the README.

  • Browse npm for packages tagged markdown-it-plugin.
  • Read the documentation at markdown-it.github.io.
  • See docs/usage.md in the repository for more usage examples.

What people use it for

  • Showing formatted README-style text on a documentation page in a website.
  • Rendering user-written notes or comments as HTML inside a Node.js app.
  • Converting Markdown content in a browser app without a build step, using a CDN build.
  • Adding custom Markdown syntax to a project through plugins.

Frequently asked questions

Is markdown-it free to use?

markdown-it is released under the MIT licence, as stated in the project's listing. Check the LICENSE file in the repository for the full terms.

What do I need to install markdown-it?

The README lists Node.js as the prerequisite and shows installation with npm install markdown-it. The README only shows npm usage.

How do I install markdown-it?

Run npm install markdown-it in your project folder. The README gives this as the installation command for Node.js.

Can I use markdown-it in the browser?

The README says you can use a CDN such as unpkg.com or esm.sh in the browser, since these mirror the npm registry.

What are alternatives to markdown-it?

Comparable projects named in the source are marked, remark, and showdown. Choose based on the features and syntax rules your project needs.

Is markdown-it a graphical editor?

No. The README describes a code library, not an editor or app, so you need to write code to use it.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

markdown-it suits JavaScript or TypeScript developers who need to render CommonMark-compliant Markdown in Node.js or browser projects, especially if they want to add custom syntax through plugins. If you only want to write Markdown documents or need a graphical tool, or your project does not use JavaScript, pick a different tool.

Install options & downloads