text/plain MIME Type — Plain Text Responses & Log File Serving
Plain UTF-8 (or ASCII) text with no markup. Browsers display text/plain directly in the viewport rather than parsing it. Used for .txt files, log output, error messages, and simple string APIs.
Used For
- robots.txt
- .txt file downloads
- Log file endpoints
- Simple health check responses
HTTP Header Example
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Hello, world!Code Examples
// Express
app.get('/robots.txt', (req, res) => {
res
.set('Content-Type', 'text/plain')
.send('User-agent: *\nDisallow: /admin')
})
// Next.js App Router
export async function GET() {
return new Response('User-agent: *\nDisallow: /admin', {
headers: { 'Content-Type': 'text/plain' },
})
}Related MIME Types
Frequently Asked Questions
What is the text/plain MIME type?
Plain UTF-8 (or ASCII) text with no markup. Browsers display text/plain directly in the viewport rather than parsing it. Used for .txt files, log output, error messages, and simple string APIs.
When should I set Content-Type: text/plain?
Set Content-Type: text/plain on HTTP responses that contain Plain Text data. robots.txt.
What file extensions use text/plain?
Files with text/plain content typically use these extensions: .txt, .log, .md.
What happens if I serve this with the wrong Content-Type?
Browsers use the Content-Type header to decide how to handle the response. Serving text/plain content with an incorrect MIME type can cause browsers to display it incorrectly, refuse to execute it (scripts), or prompt an unintended download. Modern browsers respect X-Content-Type-Options: nosniff and will not attempt to auto-detect the type.
