What is an HTML WYSIWYG editor?
WYSIWYG means "what you see is what you get": you format text the way you do in a word processor, with a toolbar and buttons, and the tool writes the HTML for you. This page has two halves that stay in sync. On top is a rich text editor; below is the HTML it produces, which you can copy. Change one and the other follows. It is the quickest way to get clean HTML for a snippet without typing tags by hand.
It fits the jobs where you need markup but not a whole page: the body of an email or a newsletter, a block for a CMS or a help-centre article, a description field that accepts HTML in an admin panel, a README section, or a table you would hate to write as <tr> and <td>. The generated HTML is simple and predictable: paragraphs, headings, lists, tables, strong and em, code blocks. There are no wrapper div elements and no class names that depend on someone's stylesheet.
The editor keeps only what it understands, and that is also what makes the output tidy. If you paste HTML from somewhere else, scripts, event handlers such as onclick, class and id attributes and unknown tags are dropped, and javascript: links do not survive. The page never saves what you write; only your choice of output view is remembered. Everything runs in your browser. To go from HTML to Markdown, there is the HTML to Markdown converter, and for the reverse the Markdown to HTML converter.
How to use the HTML editor
- Click inside the editor and write. It opens with a heading and a paragraph so you can see how the HTML below looks.
- Use the toolbar for bold, italic, underline, strikethrough and inline code; heading levels 1 to 4; bulleted and numbered lists; code block; quote; line break; and undo and redo. The clear-formatting button strips the marks (bold, colour, highlight) and turns headings and lists back into plain paragraphs.
- Colour text or highlight it with the colour pickers, and remove the colour with the clear buttons next to them.
- Insert a table, then use the table controls to add or delete columns and rows, toggle the header row, merge and split cells, or delete the table.
- Read the HTML under the editor. By default it is indented so you can read it. Turn on minify to see it without line breaks, which is what you want to paste into a single-line field.
- Switch to plain text to see only what a reader sees, with the tags removed. Tables come out with the cells separated by tabs, so they paste into a spreadsheet.
- To edit HTML you already have, paste it into the load box lower on the page and press the load button. It replaces the content of the editor. If the box is empty, a message asks you to paste some HTML first.
- Copy the HTML or the text with the copy button.
If you need to turn special characters into entities such as &, use the HTML entities tool.
Examples
The default document
Writing a title and a line gives the HTML:
<h1>Hey!</h1>
<p>Welcome to this HTML editor</p>With minify on, the same document is printed as <h1>Hey!</h1><p>Welcome to this HTML editor</p>. As plain text it is two lines: Hey! and Welcome to this HTML editor.
Cleaning pasted HTML
Pasted into the load box:
<div class="box" id="x"><p onclick="alert(1)" style="color:red">Hi <b>there</b> <a href="javascript:alert(1)">bad</a></p><script>alert(2)</script></div>What the editor holds, and the HTML below it:
<p>Hi <strong>there</strong> bad</p>The wrapper, the attributes, the script and the dangerous link are gone, and <b> became <strong>.
Colour and highlight
A word coloured red and another highlighted yellow are written with inline styles, which is how email clients expect colour:
<p>a <span style="color: rgb(255, 0, 0);">red</span> and <mark data-color="rgb(255, 255, 0)" style="background-color: rgb(255, 255, 0);">marked</mark></p>A table
A table with a header row and one data row is written as:
<table>
<tbody>
<tr>
<th>Name</th>
<th>Qty</th>
</tr>
<tr>
<td>Pen</td>
<td>3</td>
</tr>
</tbody>
</table>In the plain-text view the same table is Name, a tab, Qty, a new line, Pen, a tab and 3.
Common errors and how to fix them
- Paste some HTML first, then load it into the editor: the load box is empty. Paste markup and press the load button again.
- My images disappeared: the editor keeps links (
<a href>, only web, mail, phone, anchor and relative addresses) and underline (<u>), but has no image element, so<img>is dropped. Add images in your final markup by hand. - My classes and ids are gone: the editor drops attributes it does not manage. Add them after copying, or use the HTML in a template that styles plain elements.
- A list has a paragraph inside each item: the editor writes
<li><p>…</p></li>. It is valid HTML; remove the inner<p>if your stylesheet adds extra space.
Frequently asked questions
How do I write HTML without knowing HTML?
Format the text in the editor and copy the HTML from the panel below. Headings, bold, lists and tables all turn into the right tags.
Can I paste text from Word or a web page?
Yes, paste it in the editor. What the editor supports is kept (headings, bold, italics, lists, tables) and the rest is discarded, which removes most of the noise that Word adds.
Is the HTML safe to publish?
It is cleaner than most pasted HTML, because scripts and event attributes are removed. Even so, any site that accepts HTML should sanitise it on the server as well.
Does it support images and links?
Links yes, images no. A pasted link (<a href>) and underline are kept, but the editor has no button to create a link and no image element. Add new links and images in the final markup.
How to get the text out of HTML in code
JavaScript
DOMParser parses without running scripts, so textContent is a safe way to get the text.
const html = '<h1>Hey!</h1><p>Welcome to this <b>HTML</b> editor</p>';
const doc = new DOMParser().parseFromString(html, 'text/html');
console.log(doc.body.textContent); // Hey!Welcome to this HTML editorPython
The standard library has an HTML parser.
from html.parser import HTMLParser
class Text(HTMLParser):
def __init__(self):
super().__init__()
self.parts = []
def handle_data(self, data):
self.parts.append(data)
p = Text()
p.feed("<h1>Hey!</h1><p>Welcome to this <b>HTML</b> editor</p>")
print("".join(p.parts)) # Hey!Welcome to this HTML editor