AppDevTools
AppDevTools
/
Text Tools
HTML Stripper

HTML Stripper

client
Enter the tags to keep separated by a comma. For example, b,strong.

Documentation

What is stripping HTML?

Stripping HTML is the process of removing every HTML element from HTML code and keeping only the text content inside instead.

For example, stripping HTML tags from the HTML code below will result in the text in the following block. In this case, the h1 and h2 tags are completely removed. Therefore, you get the raw text as a result.

<h1>HTML Stripper</h1>
<h2>You can easily strip all the HTML tags using HTML Stripper</h2>
HTML Stripper
You can easily strip all the HTML tags using HTML Stripper

How to strip HTML tags programmatically in JavaScript

You can completely strip HTML tags from HTML code programmatically using regular expression assuming the text in input HTML code is safely escaped; i.e. no < and > characters inside any HTML elements.

Here is an example of how to strip HTML tags to get only the text content from HTML code in JavaScript using the built-in replace method. The similar regular expression can be used in other programming languages as well.

const html = '<h1>HTML Stripper</h1>';
// Replace everything matching an HTML element with an empty string as known as stripping it.
const text = html.replace(/<[^>]*>/g, '');

console.log(text); // HTML Stripper

How to decode HTML entities in JavaScript

Sometimes, stripped text can contain HTML entities which represent HTML special characters as known as reserved characters. An HTML entity begins with an ampersand & and ends with a semicolon ;. For example, &copy; is the HTML entity of the copyright symbol ©.

In order to get the original text, you'll have to decode HTML entities back to their corresponding characters. Fortunately, there exists a library for this purpose in most programming languages. In JavaScript, you can use the he (standing for HTML Entities) library to encode or decode HTML entities like so.

const he = require('he');

const text = 'The Euro (&#x20AC;) is the currency of the EU countries.';
// Decode the HTML entities in the text using the decode method from the he library.
const decodedText = he.decode(text);

console.log(decodedText); // The Euro (€) is the currency of the EU countries.

Related Tools

String Utilities

Counts the number of characters, words, lines, and substrings, converts a string to lowercase, uppercase, reverses a string, or splits a string with a separator.

Case Converter

Converts words or text to any case instantly, such as lowercase, uppercase, camel case, capital case, constant case, param case, pascal case, sentence case, title case, and more.

Sort Lines

Sorts lines alphanumerically and/or case-insensitively, reverses lines, shuffles lines, or adds line numbers to text with your preferred EOL for both UNIX and Windows.

Diff Checker

Compares text to find the differences between two text documents instantly with syntax highlighting. Supports over 170 programming languages.

Text Editor

Views and edits text or code with syntax highlighting and saves it into a file. Supports over 170 programming languages.

JSON Editor

Views, edits, and formats JSON data instantly with syntax highlighting and saves it into a file including JSON Viewer for in-depth JSON data inspection.

Lorem Ipsum Generator

Generates Lorem Ipsum as known as placeholder text in paragraphs, sentences, or words instantly. Supports both plain text and HTML.

URL Parser / Query String Splitter

Instantly parses a URL and splits a query string into individual components, such as protocol, path, host, port, username, password, and more.

Slug Generator

Instantly slugifies words or text to an SEO-friendly and human-readable URL slug for better SEO optimization.

Pastebin

Pastes text or code for online public viewing via a share link with syntax highlighting and an optional expiration period. Supports over 170 programming languages.

Share