Interview Question

What is HTML sanitization?

Sanitization cleans untrusted HTML before it is displayed.

💡 Concept ✅ Quick Revision 🌐 HTML

Answer

HTML sanitization removes unsafe code from HTML supplied by a user. • It keeps only allowed tags and attributes. • It helps stop harmful scripts from running. • Use a trusted sanitizer instead of making one with simple text replacement.

💡 Simple Example

<p>Allow `&lt;p&gt;Hello&lt;/p&gt;` but remove an unsafe `&lt;script&gt;` element.</p>

⚡ Quick Revision

Sanitization cleans untrusted HTML before it is displayed.