What is MIME type "application/xhtml+xml"?

A MIME type is a string that tells browsers and other tools how to handle a particular kind of file.

application/xhtml+xml is a MIME type used for serving documents written in XHTML, which combines HTML and XML standards. It tells browsers to treat the page as strict XML, so every tag must be well-formed.

Files typically served in this format include those labeled with XML, HTML, HTM, XHTML, and XHT when they adhere to XML structure.

This MIME type is ideal when you need a robust format that supports advanced XML features and enforces meticulous document structure. For more technical details, consider visiting the W3C website.

Associated file extensions

Usage Examples

HTTP Header

When serving content with this MIME type, set the Content-Type header:


    Content-Type: application/xhtml+xml    
  

HTML

In HTML, you can specify the MIME type in various elements:


    <a href="file.dat" type="application/xhtml+xml">Download file</a>    
  

Server-side (Node.js)

Setting the Content-Type header in Node.js:


    const http = require('http');    
    
    http.createServer((req, res) => {    
      res.setHeader('Content-Type', 'application/xhtml+xml');    
      res.end('Content here');    
    }).listen(3000);    
  

Associated file extensions

FAQs

What is the difference between application/xhtml+xml and text/html?

The main difference is how the browser parses the document. application/xhtml+xml triggers the XML parser, which requires strict well-formedness and stops rendering if errors occur, whereas text/html triggers the HTML parser, which is lenient and tries to fix syntax errors automatically.

Why does my page show an XML parsing error?

When content is served as application/xhtml+xml, browsers enforce strict XML rules. If your code has a single syntax error—such as an unclosed tag or an unescaped ampersand—the browser will display a parsing error (often called the "Yellow Screen of Death") instead of the page content.

How do I configure Apache to serve .xhtml files correctly?

You can configure your Apache server by adding an AddType directive to your .htaccess or configuration file. Add the line AddType application/xhtml+xml .xhtml .xht to ensure files with these extensions are served with the correct MIME type.

Can I use application/xhtml+xml for HTML5 documents?

Yes, this is often referred to as XHTML5 or the XML serialization of HTML5. However, you must ensure the HTML syntax is valid XML (e.g., self-closing tags like <br /> and quoted attributes), or the browser will fail to render the page.

Which file extensions commonly use this MIME type?

While it can be applied to standard .html files, it is most commonly associated with xhtml and xht extensions. Using these specific extensions helps developers distinguish between strict XML documents and standard HTML.

What are the benefits of using application/xhtml+xml?

It allows for the native integration of other XML namespaces, such as SVG and MathML, directly within the markup. Additionally, because the structure is guaranteed to be well-formed, the content can be easily processed by server-side XML tools.

Is application/xhtml+xml supported by all browsers?

It is supported by all modern browsers, including Chrome, Firefox, Safari, and Edge. However, legacy browsers like Internet Explorer 8 and older do not support this MIME type and will usually attempt to download the file instead of displaying it.

General FAQ

What is a MIME type?

A MIME (Multipurpose Internet Mail Extensions) type is a standard that indicates the nature and format of a document, file, or assortment of bytes. MIME types are defined and standardized in IETF's RFC 6838.

MIME types are important because they help browsers and servers understand how to process a file. When a browser receives a file from a server, it uses the MIME type to determine how to display or handle the content, whether it's an image to display, a PDF to open in a viewer, or a video to play.

MIME types consist of a type and a subtype, separated by a slash (e.g., text/html, image/jpeg, application/pdf). Some MIME types also include optional parameters.

How do I find the MIME type for a file?

You can check the file extension or use a file identification tool such as file --mime-type on the command line. Many programming languages also provide libraries to detect MIME types.

Why are multiple MIME types listed for one extension?

Different applications and historical conventions may use alternative MIME identifiers for the same kind of file. Showing them all helps ensure compatibility across systems.