If I want to redirect to another page in my HTML file, do in have to place the meta tag in the head
or can I place it at the top of the file before the DOCTYPE? Thank you.
You can't place a meta
tag above the DOCTYPE. The DOCTYPE must always be the first element in an HTML document, and meta
tags must only be placed in the head
.
Documents must consist of the following parts, in the given order:
- Optionally, a single "BOM" (U+FEFF) character.
- Any number of comments and space characters.
- A DOCTYPE.
- Any number of comments and space characters.
- The root element, in the form of an html element.
- Any number of comments and space characters.
Source: http://www.w3.org/TR/html5/syntax.html#writing
For purposes of this question, the spec says that a document must start with a DOCTYPE and be followed by a root html
element. While a meta
tag might still work, there is no guarantee of it doing so today and continuing to do so in the future.
W3C deprecates the use it, but they do offer an example on W3C:
<HEAD>
<TITLE>Don't use this!</TITLE>
<META http-equiv="refresh" content="5;http://www.example.com/newpage">
</HEAD>
<BODY>
<P>If your browser supports Refresh, you'll be transported to our
<A href="http://www.example.com/newpage">new site</A>
in 5 seconds, otherwise, select the link manually.
</BODY>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With