What is the Use of Content Type in HTML?

Learn via video course
FREE
View all courses
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
Topics Covered

The HTML content-type header is an identifier that tells the HTTP client or server the type of media or files the resource is. The content type is also known as the media type or MIME (Multipurpose Internet Mail Extensions) type.

With the help of the specified content type the user agent understands the type of content and improves the user experience by displaying the content accordingly.

Syntax

Directives

The three directives in the HTML content type are as follows:

  1. media type: The media type directive specifies the MIME (Multipurpose Internet Mail Extensions) type of the resource.
  2. charset: Charset refers to the character encoding standard in which the data will be received by the browsers.
  3. boundary: The boundary directive is used in the case of multipart entities consisting of 1 to 70 characters from a set of characters (without white spaces at the end) known to be very robust through email gateways.

Examples

How the Images are Read by the Browser with and without Setting the Content-type Header

The Content-type header information tells the browser, the type of response it is getting from the server.

How Browser Reads Image With Content-type

How Browser Reads Image Without Content-type

Content-Type in HTML Forms

The Content-Type a POST request, received after an HTML form submission, is specified by the enctype attribute on the <form> element. Code

HTML

All Possible Values of HTTP Content-type Header

The commonly used HTTP Content-Type headers are:

Content-TypeValues
Application
  • application/EDI-X12
  • application/EDIFACT
  • application/javascript
  • application/octet-stream
  • application/ogg
  • application/pdf
  • application/xhtml+xml
  • application/msword
  • application/json
  • application/ld+json
  • application/xml
  • application/zip
  • application/x-www-form-urlencoded
Audio
  • audio/mp3
  • audio/mpeg
  • audio/x-ms-wma
  • audio/x-wav
Image
  • image/gif
  • image/jpeg
  • image/png
  • image/tiff
  • image/vnd.microsoft.icon
  • image/x-icon
  • image/vnd.djvu
  • image/svg+xml
Multipart
  • multipart/mixed
  • multipart/alternative
  • multipart/form-data
Text
  • text/css
  • text/csv
  • text/html
  • text/xml
  • text/plain
Video
  • video/mpeg
  • video/mp4
  • video/x-ms-wmv
  • video/x-msvideo
  • video/x-flv
  • video/webm
  • video/quicktime
VND
  • application/vnd.oasis.opendocument.text
  • application/vnd.oasis.opendocument.spreadsheet
  • application/vnd.oasis.opendocument.presentation
  • application/vnd.oasis.opendocument.graphics
  • application/vnd.ms-excel
  • application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
  • application/vnd.ms-powerpoint
  • application/vnd.openxmlformats-officedocument.presentationml.presentation
  • application/msword
  • application/vnd.openxmlformats-officedocument.wordprocessingml.document
  • application/vnd.mozilla.xul+xml

Browser Compatibility

The following browsers support Content-Type::

  • Chrome Edge
  • Firefox Internet
  • Explorer
  • Opera
  • Safari
  • Samsung Internet

Learn more

Conclusion

  • The Content-Type Header is used to represent the original media type of the data for communication between the HTTP client and the server
  • The three directives in the HTML content type are media type, charset, and boundary.
  • By implementing the HTML content type header the user experience is enhanced, leading to the improvement of the site’s performance.