When user-supplied text is embedded into HTML, SQL queries, JSON payloads, or code strings without escaping, special characters can break the surrounding syntax โ or worse, be interpreted as executable instructions. This is the root cause of some of the most common and severe security vulnerabilities on the web.
<script> tag in unescaped HTML input can steal cookies or hijack sessions.| Mode | Use when | Characters escaped |
|---|---|---|
| HTML | Inserting text into HTML attributes or element content | & < > " ' |
| JSON String | Embedding a value inside a JSON string literal | " \ / and control chars |
| JavaScript | Injecting a value into a JS string in a template | \ ' " \n \r \t |
| SQL | Building SQL queries with string parameters (prefer parameterised queries) | ' \ |
| CSV | Outputting fields that contain commas, quotes, or newlines | Wraps field in quotes, doubles internal quotes |
| Regex | Using a dynamic string as a literal pattern in a RegExp constructor | . * + ? ^ $ { } ( ) [ ] \ | |
| Character | HTML | JSON / JS | SQL |
|---|---|---|---|
& | & | โ | โ |
< | < | โ | โ |
> | > | โ | โ |
" | " | \" | โ |
' | ' | \' | '' |
\ | โ | \\ | \\ |
| newline | โ | \n | โ |
| tab | โ | \t | โ |
Always escape at the point of output, not at the point of input. Escaping on input corrupts the stored data and means you need to know which format it was escaped for later. Store raw text, escape when rendering.
© 2026, Tinker - tools ยท calculators ยท practice games