Early Access

Meta Tags

content-type

Learn how to use the content-type meta tag to improve your site.

Defines the MIME type and character encoding for the HTML document. It sets the character set used for the HTML document, which is crucial for correctly displaying text.

Code Examples

<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
This example specifies the HTML document type with UTF-8 character encoding, ensuring correct text display and maximum compatibility.
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
While ISO-8859-1 was common in early web development, UTF-8 is now strongly recommended to support a broader range of characters and symbols.
<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
For XHTML documents, this example correctly sets the MIME type to "application/xhtml+xml" and specifies UTF-8 as the charset.
<meta http-equiv="content-type" content="" />
Not providing a "Content-Type" meta tag can lead to incorrect MIME type detection and character encoding, possibly misinterpreting the website's content.

Recommendations

  • Specify UTF-8 Encoding
    Always set the character encoding to UTF-8 to avoid issues with the display of special characters and to ensure maximum compatibility across different browsers. UTF-8 is universally supported and is the best choice for internationalization.
  • MIME Type Specification
    Although "text/html" is the default MIME type for HTML documents, explicitly defining the MIME type along with the character encoding is a good practice. It leaves no ambiguity for the browser to interpret the document type.

Related Documentation

Related Meta Tags

Defines which dynamic resources are allowed to load, thus helping to prevent cross-site scripting attacks, data injection, and other malicious attempts to exploit web page vulnerabilities.

<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' https://apis.google.com;">
Allows scripts, styles, and images to load from the site's own origin and scripts from Google APIs, tightening security by restricting external resources.

content-type

http-equiv

Defines the MIME type and character encoding for the HTML document. It sets the character set used for the HTML document, which is crucial for correctly displaying text.

<meta http-equiv="content-type" content="text/html; charset=UTF-8">
This example specifies the HTML document type with UTF-8 character encoding, ensuring correct text display and maximum compatibility.

default-style

http-equiv

Specifies the name of the preferred stylesheet to use on a web page. This allows users or user agents to choose the default stylesheet amongst many provided.

<meta http-equiv="default-style" content="Main Style">
Correct use case where "Main Style" is precisely the title of one of the page’s alternative stylesheets.

refresh

http-equiv

Used to redirect the user to a new URL after a certain number of seconds, or to refresh the current page. While it can be useful for redirecting users or refreshing content, its usage is generally discouraged in favor of server-side redirects or JavaScript for a better user experience and performance.

<meta http-equiv="refresh" content="5;url=http://example.com">
Redirects the user to "http://example.com" after 5 seconds, giving a brief moment to read any important information before the redirect.

X-UA-Compatible

http-equiv

Advises the web browser to display the webpage in compatibility view or a specific version of Internet Explorer. Primarily used to instruct Internet Explorer to use its Edge rendering engine.

<meta http-equiv="X-UA-Compatible" content="IE=edge">
Instructs Internet Explorer to use the latest available rendering engine, ensuring more modern, standards-compliant HTML & CSS features are used.