Creating a markdown previewer with React

Creating a real markdown previewer with React, and above all, doing it correctly, requires real concentration! Fortunately, with a little help anyone can do it. Here are a few tips for creating your own markdown previewer!
•
Updated on August 14, 2026
•
4 min read
Believemy logo

Creating a proper Markdown previewer with React—and doing it correctly—requires real focus! Fortunately, with a bit of help, anyone can achieve it. Here are some tips for building your own Markdown previewer!

 

Step 1 - Create the HTML and CSS

In this first step, I recommend starting by creating the HTML and CSS code.

We won’t need to create any components other than the default one provided by React: App.js.

For the HTML structure, I chose to use flexbox to place two elements side by side:

  • The left element (containing the textarea)
  • The right element (containing the previewer)

Each of these two elements takes up 50% of the space.

If you'd like, here’s the CSS I’m using for my textarea and code elements:

CSS
textarea {
  display: block;
  width: 100%;
  font-family: Arial, sans-serif;
  padding: 5px 10px;
  font-size: 1rem;
  line-height: 1.5rem;
  border-radius: .25rem;
}

code {
  padding: 2px 4px;
  font-size: .9em;
  color: #c7254e;
  background-color: #f9f2f4;
  border-radius: 4px;
}

I also suggest adding a default value to your textarea. This is a Markdown text that will provide content when your page loads:

HTML
# `Previewer - Believemy`\n### Oh! Magic!\nActually, not really: this is called Markdown, and this project built entirely with React converts it into *HTML*!\n\n### Use Cases\n* *italic*\n* **bold**\n* `monospace`\n* ~~strikethrough~~\n* # h1\n* ## h2\n* ### h3\n* #### etc\n[Believemy](https://believemy.com)

Let’s meet in the next step!

Have fun!

If you want, you can see everything possible with Markdown by checking out this guide.

 

Step 2 - Detect Text Changes

In this second step, I recommend detecting text changes in our textarea.

I won’t provide specific hints for this step; I’m confident you’ll be able to figure it out on your own.

 

Step 3 - Install MarkedJS

To convert our Markdown into HTML, we’ll take advantage of the excellent library Marked.

You can install it using the following command:

RUBY
npm install --save marked

Then, import Marked from the library, just like we’ve done with React since the beginning.

 

Step 4 - Convert Text to HTML

To finish this project, we’ll need to convert the Markdown into HTML.

By now, you should already have detected text changes from the user. I’m sure you’ll manage to retrieve the text itself. If not, you can check the end of this step for some valuable hints.

To convert our Markdown into HTML, we installed the Marked library in the previous step. Here’s how it works:

JAVASCRIPT
Marked(text); // Returns the Markdown text as HTML

Knowing this, you just need to find a way to add the generated HTML directly into our right element (the previewer). There’s a trick to implementing this; I’ll let you figure it out. You can also check Hint B below if needed.

 

Hints

Hint A

If you’re having trouble retrieving the text entered by the user, remember that React is just JavaScript. You can retrieve the entered text from the event triggered by JavaScript.

JAVASCRIPT
event.target.value

Simply detect this event by passing it as a parameter via an anonymous arrow function, just like we managed to change the name of our student by passing "Elon" as a parameter.

 

Hint B

If you’re struggling to insert your HTML code directly with React: that’s normal. React has built-in security that prevents adding HTML into JSX. To disable this, you can use the dangerouslySetInnerHTML attribute.

Here’s how to activate it (it’s very simple): https://reactjs.org/docs/dom-elements.html#dangerouslysetinnerhtml

This project is your very first project with React. It’s not very difficult, but it’s not very easy either. I know you can do it. Take your time, breathe, drink some hot chocolate or coffee, and don’t hesitate to search online instead of immediately checking the solution: it’s the best way to learn. Everything you need has been covered in our lessons.

I believe in you!

 

Solution

Warning: you’re about to view the solution. Stop here and really try to create your Markdown previewer yourself—you’re capable. Nothing is more satisfying than completing a project, even if it takes some time and effort.

Here’s the link to the full video solution: https://www.youtube.com/watch?v=RA1zlN3roJI

Category: Developers

Share this article

Want to help us? Share this article on your networks or even better: on your site, in an article or in your newsletter.

Believemy logo
Comments (0)

You need to be logged in to comment on this article: log in or sign up.

Read next

Code faster with React using these techniques

Learn how to code faster with React thanks to simple but effective techniques used by experienced developers.

December 9, 2024

Syntax highlighting with HTML and CSS

If you have a blog or a portfolio on which you want to present code, whether HTML / JavaScript or CSS code extracts, you have undoubtedly come up against a problem: how do you activate syntax highlighting to make it look as if you had put the code in a code editor? In this article, we'll look at how to do it.

December 9, 2024

Understanding .env files with ReactJS

Find out how to really use the .env file with React or NextJS so you never make a mistake again.

December 9, 2024

Create a clean, modern timeline using html and css

Whether you want to show a purchasing process, the highlights of your career on your portfolio, or anything else, learn how to create a sleek, modern timeline to show it off!

December 9, 2024

When should you use brackets with React?

To put brackets or not to put brackets... This can be a complicated subject when you're new to React! Let's find out together when to use brackets and when not to.

December 9, 2024

How to install TinyMCE in a project using React or NextJS?

Find out how to install TinyMCE in React or NextJS and fully customize it with plugins to match your projects.

December 6, 2024

What's new in React 19

React 19 has just been announced by the Meta team. Powerful new features have been introduced almost two years after the release of React 18.3. Let's find out what's new with React 19.

December 5, 2024

The complete guide to React Toastify

Discover the complete guide to React Toastify, a powerful library for managing notifications in React. Learn how to install, configure and customise all your toasts easily with concrete examples and advanced tips.

December 6, 2024

Become the solopreneur you dream of being.

First project, career change, business launch: access our courses, practice on real-world cases, and move forward with clear guidance.