I have a site which is divided into templates and sub-items for tempates in the backend's template language.

However the sub-templates which are embedded into main templates each start with<!DOCTYPE html>. So, when I render a template as frontend there are multiple <!DOCTYPE html>s.

Is it bad for SEO to have multiple <!DOCTYPE html>s in a single page in the middle of the page and one in the top?

Should I remove them?

  • Is this !doctype tag inside an <iframe> tag
    – Salaros
    Commented Jan 19, 2018 at 16:55
  • @Salaros No, they are all in one page. No, <iframe>. Then backend has a templating system where some parts are divided in smaller pieces. When rendered they are a normal page.
    – Kotlinboy
    Commented Jan 19, 2018 at 22:25

3 Answers 3


It's not going to make any difference to SEO, however, my main concern would be browser rendering, since it's technically invalid markup.

However, I suspect most browsers will simply ignore it.


Applying multiple elements <!DOCTYPE html> will throw an error in the HTML5 validator. Any error on the web page has a direct or indirect effect on the search engine optimization of these webpages. In your case.

Parsing is a very significant process within the rendering engine. Parsing a document means translating it to a structure the code can use. The result of parsing is usually a tree of nodes that represent the structure of the document. This is called a parse tree or a syntax tree. Parsing is based on the syntax rules the document obeys: the language or format it was written in. Every format you can parse must have deterministic grammar consisting of vocabulary and syntax rules.

Parsing can be separated into two sub processes: lexical analysis and syntax analysis.

Lexical analysis is the process of breaking the input into tokens. Tokens are the language vocabulary: the collection of valid building blocks. In human language it will consist of all the words that appear in the dictionary for that language.

Syntax analysis is the applying of the language syntax rules.

Parsers usually divide the work between two components: the lexer (sometimes called tokenizer) that is responsible for breaking the input into valid tokens, and the parser that is responsible for constructing the parse tree by analyzing the document structure according to the language syntax rules.

The parsing process is iterative. The parser will usually ask the lexer for a new token and try to match the token with one of the syntax rules. If a rule is matched, a node corresponding to the token will be added to the parse tree and the parser will ask for another token.

If no rule matches, the parser will store the token internally, and keep asking for tokens until a rule matching all the internally stored tokens is found. If no rule is found then the parser will raise an exception. This means the document was not valid and contained syntax errors.

Source: How Browsers Work: Behind the scenes of modern web browsers of HTML5 Rock.

You can see how much work the browser does when opening a webpage. This parsing takes some time for the browser. Now imagine that in the source code of open web pages have errors. Accordingly, the browser parsing time is increased. Accordingly, the speed of downloading the webpage decreases, but this is a signal of Google's search ranking - both for desktops and for mobile. Thus, breaking the standard of HTML (source code errors - this is a violation of the accepted standard) you are contributing a decrease in the search rank of your webpages, that is, a negative SEO.

A possible solution to this problem is the use of a tag code.

  • I'm not embedding code anywhere. The sub-templates are blocks that are embedded in the main template and rendered, This is some framework related stuff. So it's a complete page. So, basically you have parts of the HTML where there are doctypes in the middle.
    – Kotlinboy
    Commented Jan 20, 2018 at 11:53
  • Thanks! I removed the doctypes as there was no need for them to be there. I was just curious.
    – Kotlinboy
    Commented Jan 20, 2018 at 11:53
  • @Kotlinboy "So it's a complete page" - so presumably you have additional head, title, meta, body tags etc. as well as the DOCTYPE you mentioned?
    – DocRoot
    Commented Feb 1, 2018 at 19:17
  • @DocRoot No, only ``DOCTYPE. The templates are blocks of HTML. DOCTYPE` may have been added by the author to denote that this is where a block starts. These blocks combine to make a complete page
    – Kotlinboy
    Commented Feb 2, 2018 at 6:03
  • @DocRoot For example you might have multiple comments in a page. You don't know how many times theses comments are displayed. So, you create a comment-item.html block and in your template language(which is mixed HTML) loop through the comment items in DB and render the comment-item.html with the DB data. So, how many ever comments there are there will be DOCTYPEs in the beginning of those comments.
    – Kotlinboy
    Commented Feb 2, 2018 at 6:06

The specification says that it needs to be the first thing in your document, before the <html> or <head> elements.


If you have them further down the page they will probably be ignored, but it depends on the browser implementation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.