RawText component renders its input as raw HTML without escaping. This is useful for rendering pre-sanitized HTML content, such as markdown-converted text or trusted HTML from a CMS.
Constructor
The HTML string to render. This content will be inserted directly into the DOM without escaping.
Optional key for this component.
Basic usage
Render HTML content from a trusted source:With markdown conversion
Combine with a markdown parser to render markdown as HTML:Server-side rendering
RawText works seamlessly with server-side rendering:
Security best practices
Always sanitize user input
Always sanitize user input
Never pass unsanitized user input to
RawText. Use a library like html to sanitize content:Use Text for plain content
Use Text for plain content
If you just need to display plain text, use the
Text component instead. It automatically escapes HTML:Validate content sources
Validate content sources
Only use
RawText with content from trusted sources:✅ Safe sources:- Markdown converted to HTML by your server
- HTML from your CMS after sanitization
- Static HTML templates you control
- Pre-validated API responses
- User comments or posts
- URL parameters
- Form inputs
- Third-party APIs without validation
Content Security Policy
Content Security Policy
Add a Content Security Policy header to mitigate XSS risks:
Comparison with Text
| Feature | Text | RawText |
|---|---|---|
| HTML escaping | ✅ Automatic | ❌ None |
| XSS protection | ✅ Built-in | ❌ Manual |
| Use case | Plain text | Pre-sanitized HTML |
| Performance | Fast | Fast |
| Accessibility | Automatic | Depends on HTML |
Related
- Text - Safe text rendering with automatic escaping
- DomComponent - Type-safe HTML element creation
- SEO & Meta - Adding meta tags and structured data