Need to remove HTML tags from text? This guide covers everything you need to know about HTML stripping via API, including handling entities, preserving structure, and security considerations.
What is HTML Stripping?
HTML stripping removes all HTML tags from content, leaving only the plain text. This is useful for extracting readable content from web pages, sanitizing user input, and preparing text for analysis or display in non-HTML contexts.
Example: "<p>Hello <strong>World</strong></p>" becomes "Hello World"
Important Considerations
When stripping HTML, consider:
- HTML entities: & should become &, become spaces
- Whitespace: Multiple tags may create extra whitespace
- Script tags: Content inside <script> should be removed
- Line breaks: <br> and <p> might need newlines
Using the Strip HTML API
TinyFn provides a simple endpoint to strip HTML:
POST https://api.tinyfn.io/v1/text/strip-html
Headers: X-API-Key: your-api-key
Content-Type: application/json
{
"html": "<p>Hello <strong>World</strong>!</p>",
"decode_entities": true
}
{
"text": "Hello World!",
"original_length": 37,
"text_length": 12
}
Parameters
| Parameter | Type | Description |
|---|---|---|
html |
string | The HTML content to strip (required) |
decode_entities |
boolean | Convert HTML entities to characters (default: true) |
preserve_newlines |
boolean | Convert block elements to newlines (default: false) |
remove_scripts |
boolean | Remove script and style content (default: true) |
Code Examples
JavaScript / Node.js
const response = await fetch(
'https://api.tinyfn.io/v1/text/strip-html',
{
method: 'POST',
headers: {
'X-API-Key': 'your-api-key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
html: '<p>Hello <strong>World</strong>!</p>',
decode_entities: true
})
}
);
const result = await response.json();
console.log(result.text); // "Hello World!"
Python
import requests
response = requests.post(
'https://api.tinyfn.io/v1/text/strip-html',
headers={'X-API-Key': 'your-api-key'},
json={'html': '<p>Hello <strong>World</strong>!</p>'}
)
result = response.json()
print(result['text']) # "Hello World!"
cURL
curl -X POST "https://api.tinyfn.io/v1/text/strip-html" \
-H "X-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{"html": "<p>Hello <strong>World</strong>!</p>"}'
Common Use Cases
- Content Extraction: Get plain text from web pages
- Search Indexing: Prepare content for full-text search
- Email Generation: Create plain text version of HTML emails
- Text Analysis: Analyze content without markup
- Data Export: Convert HTML to plain text for CSV/TSV
Best Practices
- Decode entities: Always convert HTML entities to characters
- Remove scripts: Strip script and style tags for clean text
- Handle whitespace: Normalize multiple spaces after stripping
- Consider structure: Preserve paragraphs with newlines when needed
Use via MCP
Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:
{
"mcpServers": {
"tinyfn-text": {
"url": "https://api.tinyfn.io/mcp/text/",
"headers": {
"X-API-Key": "your-api-key"
}
}
}
}
See all text analysis tools available via MCP in our Text Analysis MCP Tools for AI Agents guide.