HTML Tag Stripper

Remove lexical HTML tags, comments, and declarations while retaining raw text and character references; the result is not sanitized markup.

Description

Removing lexical HTML tags yields concatenated source text tokens.

Removing lexical HTML tags yields concatenated source text tokens. That text can still include character references and raw element contents.1, 2

Remove lexical HTML tags, comments, and declarations while retaining raw text and character references; the result is not sanitized markup.

When to use HTML Tag Stripper

Use this tool to remove lexical HTML tags, comments, and declarations while retaining raw text and character references; the result is not sanitized markup.

Paste the HTML source to transform. Compare the returned source or text with the input using the lexical rules below.

How to use HTML Tag Stripper and understand its results

  1. Paste the HTML source to transform. Compare the returned source or text with the input using the lexical rules below.
  2. Enter html using the field table and calculation rules, then run the tool.
  3. Read text. The explanation below defines the units, signs, ordering and any flags or placeholder values.
  4. If the tool reports an input issue, correct the values and run it again. Apply the stated assumptions when interpreting a successfully returned result.
Input fieldMeaningValue type; see rules belowRequirement
htmlHTML source.string; maximum length: 1000000Required

Paste HTML source. The shared scanner distinguishes tags, comments, declarations and raw-text elements; keep only text tokens in source order. Return their direct concatenation without inserting spaces or decoding entities. Script/style contents are retained.3, 4

text=join(all text-token raw strings, empty separator)

Units, indexing, boundary conditions and exceptional cases are defined in the calculation rules above.

Output fieldMeaningValue type
textText left after removing lexical markup.string; maximum length: 1000000
json
{
  "input": {
    "html": "<p>Hello <b>world</b> &amp; friends</p>"
  },
  "output": {
    "text": "Hello world &amp; friends"
  }
}

Limitations and assumptions

The scanner is not a browser DOM parser. This result is not sanitized markup: malformed tags and literal markup inside raw-text elements can remain, so handle it as text.

Numeric inputs must be finite. Follow the calculation-specific rules for overflow, underflow and exceptional cases. Extremely large text inputs are rejected. Missing required fields, extra fields, wrong value types and violations of the calculation rules are input errors.

Alternative or Complementary methods

Use HTML Whitespace Collapser: Collapse ASCII whitespace in lexical text nodes while preserving tags, attributes, comments, and preformatted or raw-text element contents. For a complementary task, use HTML Comment Remover: Remove lexical HTML comments while preserving comment-like text inside script, style, title, and textarea elements.

Further background: HTML Standard: Tokenization.

References

  1. HTML Tag Stripper — tool.io

  2. HTML Standard: Tokenization — WHATWG

  3. HTML Tag Counter — tool.io

  4. HTML Attribute Parser — tool.io

Similar or alternative tools

  • HTML Whitespace Collapser

    Collapse ASCII whitespace in lexical text nodes while preserving tags, attributes, comments, and preformatted or raw-text element contents.

  • HTML Comment Remover

    Remove lexical HTML comments while preserving comment-like text inside script, style, title, and textarea elements.

Don't forget to set a bookmark for tool.io!
Privacy | Imprint | Cookies