contacara

How to count the text of an HTML page

HTML contains tags, attributes and sometimes scripts and styles beyond visible prose. Select the article and inspect the copied result. Technical extraction should state its property and container because document text is not always visible text.

Different measurable objects

Source delivered to clients, article prose and all visible screen text are different legitimate selections. Code includes classes, URLs, metadata and instructions; an article may be surrounded by menus and forms.

Define heading, summary, body and captions with navigation excluded, for example. Repeated headers may be one reused element or ten encountered instances. Purpose decides; HTML itself does not define scope.

A controlled source comparison

Literal Italian <p>Ciao <strong>mondo</strong>!</p> has thirty-five characters and six words locally, including tag-name sequences. Separate Ciao mondo! has eleven and two.

This compares known strings rather than browser rendering. Pasting code does not import a page or semantically remove tags. Prepare simple phrases manually when suitable; define and extract a real page’s area first.

Understand textContent

textContent reads node text, potentially including script, style and invisible material, as MDN documents. Whole-document extraction therefore need not equal visible article content.

A deliberately scoped node can work correctly. Verify claims about visible words and ask which selector or container produced a technical report. “All page text” can include menus, footer and accessory content.

The p tree contains Ciao, strong containing mondo, and an exclamation mark. Literal tags belong to source rather than the read phrase.
Simplified tree of the guide’s fragment, not automatic extraction of a whole page. Open full-size JPG

Understand innerText and copying

innerText considers rendered text; MDN describes differences from textContent and exceptions for detached or unrendered elements. It resembles some copying behavior without universally representing every screen.

Select intended body, paste into the counter and inspect actual arrivals. Expanded menus, panels and interactive components complicate scope; copying introduces separators too. Automation needs a stable documented extraction rule verified beyond one page.

Entities and notation differ

Source &amp; represents &. Source counts measure notation; interpreted counts measure the resulting character. Nonbreaking references follow the same principle.

A technical article may intentionally show literal entities; decoding again destroys examples. Avoid global substitutions ignoring code roles. Compare page and matching source and decode once at the correct stage, retaining what readers should see.

Stripping tags can damage boundaries

Deleting tag-shaped strings may merge paragraph boundaries. Adding spaces around every tag may split a word with internal emphasis. Structure matters beyond brackets.

Choose table cells, rows or columns explicitly. Values can become ambiguously associated with later labels. Check paragraph transitions, lists and tables. Technical extraction should use an HTML parser with declared separator conventions and representative tests.

Inventory accessory fields

Image descriptions, control labels, tab titles and search descriptions may be writing deliverables without appearing in body selections. Do not assume inclusion or dismiss attribute text.

Count fields separately with units and locations. Agree whether repeated phrases are multiple instances or reused strings. Body corrections may not update alt text or descriptions. Reports should identify each element instead of hiding it within a total.

Specify dynamic state

Clicks, searches and data loading can reveal more text. Record closed or open panels, language and filters. The count describes a selection under particular conditions.

High totals suggest navigation, recommendations, repeats or technical text; low totals suggest captions, boxes and later-loaded content. Repair the selected copy and recount. See pasting without formatting for retained characters and lost presentation.

Literal source and phrase

Input stringCharactersWordsInterpretation
<p>Ciao <strong>mondo</strong>!</p>356Source including tags
Ciao mondo!112Separately prepared phrase
Local string-counting experiment rather than automatic DOM extraction. Full pages need selected containers and verified output.

Sources and checks

Open the tool