HTTP Content-Type Header

HTTP Content-Type header is used to specify the HTTP content type. The Content-Type header can be different values that are defined previously by the HTTP and related standards. The Content-Type header can be used to set the content or HTTP data as image, sound, video, text, etc. The content-type is very useful to define a content type in detail. The client makes a request with its browser to the specific web page or URL. The web server returns some data which can be in different formats. The content-type is added by the server in general in order to provide information about the data. So the client web browser can interpret the provided data properly.

As the Content-Type is specified in the HTTP standard all popular web browsers like Google Chrome, Mozilla Firefox, Internet Explorer, Safari, Opera supports the HTTP Content-Type header and related data presentations.

HTTP Content-Type Syntax

The HTTP Content-Type header uses the following syntax. The Content-Type can be expressed as uppercase (CONTENT-TYPE) or lowercase (content-type) there is no restriction. But the standard way is expressing as Content-Type.

Content-Type: text/html; charset=UTF-8
  • The : is used to separate the Content-Type header from the content-type values.
  • text/html is the media type part that sets the content as text where the text is the category and html is the subcategory.
  • charset=UTF-8 specifies the HTML type is encoded as UTF-8. Alternatively, it can be set UTF-16 or other encoding formats like ASCII, etc.

Content-Type Directives

Contet-Type may use different directives like media type, charset or boundary. We have allready examined the media type as text/html and charset as UTF-8 in the syntax part. The boundary directive is used to set the size for the multipart entities.

All HTTP Content-Type Header Values

TypeValue
Applicationapplication/EDI-X12
application/EDIFACT
application/javascript
application/octet-stream
application/ogg
application/pdf
application/xhtml+xml
application/x-shockwave-flash
application/json
application/ld+json
application/xml
application/zip
application/x-www-form-urlencoded
Audioaudio/mpeg
audio/x-ms-wma
audio/vnd.rn-realaudio
audio/x-wav
Imageimage/gif
image/jpeg
image/png
image/tiff
image/vnd.microsoft.icon
image/x-icon
image/vnd.djvu
image/svg+xml
Multipartmultipart/mixed
multipart/alternative
multipart/related (using by MHTML (HTML mail).)
multipart/form-data
Texttext/css
text/csv
text/html
text/javascript (obsolete)
text/plain
text/xml
Videovideo/mpeg
video/mp4
video/quicktime
video/x-ms-wmv
video/x-msvideo
video/x-flv
video/webm
VNDapplication/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

Content Types

Below the content types and their explanation can be found. These are also called as MIME types.

ExtensionExplantionContent-Type
.aacAAC audioaudio/aac
.abwAbiWord documentapplication/x-abiword
.arcArchive document (multiple files embedded)application/x-freearc
.aviAVI: Audio Video Interleavevideo/x-msvideo
.azwAmazon Kindle eBook formatapplication/vnd.amazon.ebook
.binAny kind of binary dataapplication/octet-stream
.bmpWindows OS/2 Bitmap Graphicsimage/bmp
.bzBZip archiveapplication/x-bzip
.bz2BZip2 archiveapplication/x-bzip2
.cshC-Shell scriptapplication/x-csh
.cssCascading Style Sheets (CSS)text/css
.csvComma-separated values (CSV)text/csv
.docMicrosoft Wordapplication/msword
.docxMicrosoft Word (OpenXML)application/vnd.openxmlformats-officedocument.wordprocessingml.document
.eotMS Embedded OpenType fontsapplication/vnd.ms-fontobject
.epubElectronic publication (EPUB)application/epub+zip
.gzGZip Compressed Archiveapplication/gzip
.gifGraphics Interchange Format (GIF)image/gif
.htm
.html
HyperText Markup Language (HTML)text/html
.icoIcon formatimage/vnd.microsoft.icon
.icsiCalendar formattext/calendar
.jarJava Archive (JAR)application/java-archive
.jpeg
.jpg
JPEG imagesimage/jpeg
.jsJavaScripttext/javascript
.jsonJSON formatapplication/json
.jsonldJSON-LD formatapplication/ld+json
.mid
.midi
Musical Instrument Digital Interface (MIDI)audio/midi audio/x-midi
.mjsJavaScript moduletext/javascript
.mp3MP3 audioaudio/mpeg
.cdaCD audioapplication/x-cdf
.mp4MP4 audiovideo/mp4
.mpegMPEG Videovideo/mpeg
.mpkgApple Installer Packageapplication/vnd.apple.installer+xml
.odpOpenDocument presentation documentapplication/vnd.oasis.opendocument.presentation
.odsOpenDocument spreadsheet documentapplication/vnd.oasis.opendocument.spreadsheet
.odtOpenDocument text documentapplication/vnd.oasis.opendocument.text
.ogaOGG audioaudio/ogg
.ogvOGG videovideo/ogg
.ogxOGGapplication/ogg
.opusOpus audioaudio/opus
.otfOpenType fontfont/otf
.pngPortable Network Graphicsimage/png
.pdfAdobe Portable Document Format (PDF)application/pdf
.phpHypertext Preprocessor (Personal Home Page)application/x-httpd-php
.pptMicrosoft PowerPointapplication/vnd.ms-powerpoint
.pptxMicrosoft PowerPoint (OpenXML)application/vnd.openxmlformats-officedocument.presentationml.presentation
.rarRAR archiveapplication/vnd.rar
.rtfRich Text Format (RTF)application/rtf
.shBourne shell scriptapplication/x-sh
.svgScalable Vector Graphics (SVG)image/svg+xml
.swfSmall web format (SWF) or Adobe Flash documentapplication/x-shockwave-flash
.tarTape Archive (TAR)application/x-tar
.tif
.tiff
Tagged Image File Format (TIFF)image/tiff
.tsMPEG transport streamvideo/mp2t
.ttfTrueType Fontfont/ttf
.txtText, (generally ASCII or ISO 8859-n)text/plain
.vsdMicrosoft Visioapplication/vnd.visio
.wavWaveform Audio Formataudio/wav
.webaWEBM audioaudio/webm
.webmWEBM videovideo/webm
.webpWEBP imageimage/webp
.woffWeb Open Font Format (WOFF)font/woff
.woff2Web Open Font Format (WOFF)font/woff2
.xhtmlXHTMLapplication/xhtml+xml
.xlsMicrosoft Excelapplication/vnd.ms-excel
.xlsxMicrosoft Excel (OpenXML)application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.xmlXMLapplication/xml
.xulXULapplication/vnd.mozilla.xul+xml
.zipZIP archiveapplication/zip
.3gp3GPP audio/video containervideo/3gpp
audio/3gpp if it doesn’t contain video
.3g23GPP2 audio/video containervideo/3gpp2
audio/3gpp2 if it doesn’t contain video
.7z7-zip archiveapplication/x-7z-compressed

Specify Content-Type with PHP

The PHP applications can set the Content-Type of the HTTP response. The header() method of the PHP can be used to set content type. The the content ot data should be provided to the reponse.

<?php

//Set Content Type as image png
header('Content-type: image/png');

//with header Content type
echo file_get_contents("https://wisetut.com/image.png");

?>

Leave a Comment