HTML to BBCode: Convert Formatted Text for Forums
November 11, 2026 · 11 min read
HTML to BBCode: How to Convert Formatted Text for Forums
Converting HTML to BBCode means swapping each HTML tag for the square-bracket tag a forum understands. <b> becomes [b], a link becomes [url=...], and a bulleted list becomes [list]. About a dozen tags translate cleanly. The rest, from CSS to tables, needs a decision. This guide gives you the mapping, a working script and a no-code route.
How Do You Convert HTML to BBCode?
You have three practical routes, and the right one depends on how much HTML you're moving. BBCode and HTML are both markup languages (our Markdown vs markup explainer covers what that means), but BBCode's vocabulary is far smaller. So every route is really a translation with losses.
For a short post, edit by hand. Swap the tags using the table below, delete anything with no equivalent, and paste the result into the reply box. It takes a few minutes and you control every choice.
A longer page is easier through Markdown. Our HTML to Markdown tool cleans up the source, and the markup converter writes BBCode from that Markdown. Both run in your browser.
Bulk jobs, such as moving hundreds of old articles onto a board, call for a script. A short DOM-based function, shown further down, handles nesting and attributes that trip up search-and-replace.
HTML Tags With a Direct BBCode Translation
These are the tags where an HTML to BBCode swap is mechanical. The third column lists what tends to go wrong.
| HTML | BBCode | Catch |
|---|---|---|
<b>, <strong> | [b]text[/b] | Bold set through CSS on a <span> has no tag to convert |
<i>, <em> | [i]text[/i] | Some scripts wrongly map <em> to [b] |
<u> | [u]text[/u] | Rarely a problem, since phpBB's default help lists it |
<s>, <del> | [s]text[/s] | Not in phpBB's default tags, and other boards name it differently |
<a href="..."> | [url=address]text[/url] | Relative links like /about break once they leave your site |
<img src="..."> | [img]address[/img] | The alt text is dropped, and the image must already be online |
<ul> and <li> | [list] with [*] items | Items don't need a closing tag |
<ol> | [list=1] | phpBB also accepts [list=a] for letters |
<blockquote> | [quote]text[/quote] | A cite attribute doesn't carry over |
<pre>, <code> | [code]text[/code] | Many boards show it as a separate box, even mid-sentence |
<br> | a plain line break | Most forums turn every newline into a line break, so newlines in the HTML source show up too |
Color and size do have tags, [color=] and [size=], but in HTML they live in style attributes. A converter has to read the CSS to recover them, and most don't.
Here's how a typical paragraph translates:
<p>Read the <a href="https://example.com/notes">patch notes</a> before you <strong>update</strong>.</p>
Read the [url=https://example.com/notes]patch notes[/url] before you [b]update[/b].
The <p> tag disappears. A blank line between paragraphs does the same job in BBCode.
What Has No BBCode Equivalent
Real-world HTML is mostly layout, and layout is exactly what BBCode leaves to the forum's theme. Decide what happens to each of these before you convert, so the result is predictable.
- CSS classes, ids and
<style>blocks. Drop them. The board's own stylesheet controls how posts look, and you can't add to it. HTML saved from Word is full of them, and our guide to converting Word to HTML shows cleaner exports. - Inline style attributes. Drop them, or translate the occasional color or font size by hand into
[color=]or[size=]. <div>,<span>and<section>. Keep the text and turn each block into its own paragraph.- Headings
<h1>to<h6>. Turn them into a bold line, with a larger[size]if the board supports it. - Tables. Use
[table]only where the board has it. Otherwise flatten each row into a line of text. <iframe>video and map embeds. Replace them with a plain[url]link to the page.- Forms, buttons and
<script>. Delete them. No forum will run them.
Watch for one more trap: literal square brackets in your text. Some forums parse the [b] in a sentence like press [b] to brake as a real tag, so formatting leaks into the text after it. Rephrase it, or check whether your board offers a no-parse tag.
Does BBCode Support Headings and Tables?
Not in the core set most boards start from. phpBB's BBCode help file covers bold, italic, underline, color, size, quotes, code, lists, links, email, images and attachments. It has nothing for headings, tables or horizontal rules.
For headings, the usual stand-in is size plus bold. phpBB's help describes [size=] as a percentage from 20 (very small) to 200 (very large) by default:
[size=150][b]Patch 1.4 notes[/b][/size]
On a stock phpBB board, that renders as large bold text, which reads as a heading. Other forum software uses different size scales, so the same number can look very different elsewhere.
Tables and rules depend on the board. Some forum packages ship a [table] tag with [tr], [th] and [td], and phpBB admins can add their own tags through Custom BBCodes. If your target board doesn't list a table tag, write each row as plain text with a separator, such as Low | 90 fps. Cells merged with colspan or rowspan can't span plain-text rows, so repeat their text in every slot they covered.
Convert HTML to BBCode Through Markdown
Markdown makes a useful halfway point because you can read it. You see the structure in plain text, fix anything odd, and only then turn it into brackets. The HTML-to-Markdown step has its own guide, how to convert HTML to Markdown, so here's the short version.
- Paste the HTML into the HTML to Markdown tool. It converts with turndown plus GFM and loads the result into an editor with a live preview.
- Check the preview. Delete leftover layout text, and fix headings or lists that came through oddly.
- Copy the Markdown into the markup converter, set From to Markdown and To to BBCode, and copy the output.
We tested this pipeline on a sample post. Headings came out as [size] plus [b] (an H2 became [size=170]). Pipe tables became [table] rows, <u> survived as [u], and <hr> became [hr]. Image alt text and any inline styles were gone, as expected. The same tool also writes reStructuredText, AsciiDoc, MediaWiki, Textile and Org mode, and our overview of Markdown converters covers format conversion more broadly.
Here's the Markdown that step one produces for a short forum post. Edit it and watch the preview before moving on to BBCode:
We prefer this route for one-off posts. Tags hide structure, and Markdown shows you a broken list before your forum readers do. The limitation is that colors and font sizes have no Markdown form, so they're lost on the way through.
A Small HTML to BBCode Script That Keeps Links Intact
Regex looks tempting, and it breaks in predictable ways. Tags nest, attributes come in any order, and an element can span several lines. A blunt cleanup step, such as replacing every // with /, also turns https:// into a broken link. A parser avoids all of that.
This function uses the browser's DOMParser, walks the tree, and writes BBCode for the tags in the table above:
const WRAP = { B: "b", STRONG: "b", I: "i", EM: "i", U: "u", S: "s", DEL: "s" };
const SKIP = ["SCRIPT", "STYLE", "IFRAME", "FORM"];
function htmlToBBCode(html) {
const doc = new DOMParser().parseFromString(html, "text/html");
return walk(doc.body).replace(/ +\n/g, "\n").replace(/\n{3,}/g, "\n\n").trim();
}
function walk(node) {
let out = "";
for (const el of node.childNodes) {
if (el.nodeType === 3) {
// Text: collapse whitespace, skip indentation after line breaks
const text = el.textContent.replace(/\s+/g, " ");
if (text.trim() || (out && !out.endsWith("\n"))) out += text;
continue;
}
if (el.nodeType !== 1 || SKIP.includes(el.tagName)) continue;
const tag = el.tagName;
const inner = walk(el);
if (WRAP[tag]) out += `[${WRAP[tag]}]${inner}[/${WRAP[tag]}]`;
else if (tag === "A") out += `[url=${el.getAttribute("href")}]${inner}[/url]`;
else if (tag === "IMG") out += `[img]${el.getAttribute("src")}[/img]`;
else if (tag === "UL") out += `\n[list]\n${inner}[/list]\n`;
else if (tag === "OL") out += `\n[list=1]\n${inner}[/list]\n`;
else if (tag === "LI") out += `[*]${inner.trim()}\n`;
else if (tag === "BLOCKQUOTE") out += `\n[quote]${inner.trim()}[/quote]\n`;
else if (tag === "PRE") out += `\n[code]${el.textContent}[/code]\n`;
else if (tag === "CODE") out += `[code]${el.textContent}[/code]`;
else if (/^H[1-6]$/.test(tag)) out += `\n[size=150][b]${inner.trim()}[/b][/size]\n`;
else if (tag === "TR") out += [...el.cells].map((c) => walk(c).trim()).join(" | ") + "\n";
else if (tag === "BR") out += "\n";
else if (["P", "DIV", "TABLE"].includes(tag)) out += `\n${inner.trim()}\n`;
else out += inner; // span, font, section: keep the text, drop the tag
}
return out;
}
Run it in the browser console with htmlToBBCode(yourHtml). Nested lists come out as nested [list] blocks, https:// addresses stay whole, and tables become Mode | FPS style rows. Script and style contents are skipped entirely.
Two things it leaves to you. It copies href values exactly as written, so relative links stay relative until you add the domain. It also doesn't escape square brackets already in the text. Node.js doesn't ship a DOMParser, so in Node you'd supply one from a DOM library such as jsdom.
Checking the Converted Post on Your Forum
No single BBCode standard governs every forum. Each forum package documents its own tag set, and admins switch tags on or add new ones. Treat any converter's output as a draft for one specific board.
Find that board's BBCode help page first, then compare it with what you're about to post. Watch for these problems:
- Tags closed out of order. phpBB's help calls
[b][u]text[/b][/u]incorrect. Close the inner tag first. - Unknown tags. A
[table],[hr]or[s]the board doesn't support prints as literal text. - List items outside a list. Each
[*]needs a[list]around it. - Images that live only on your computer. phpBB's help says an image must already be available online, so host it or use the attachment feature.
- Relative links. Anything starting with
/points at the forum, not your old site.
Then hit Preview before you post. The forum's own preview runs its real parser, so it's the only check that counts. Our tools change text, but neither one renders BBCode.
More Questions About Converting Forum Posts
Moving HTML to BBCode works best when you treat it as a translation, not a copy. Map the dozen tags that have equivalents, decide in advance what happens to styles, embeds and tables, and check the result in your forum's preview. For a quick no-code version, clean the HTML into Markdown first, then turn it into forum tags with the markup converter.