Search code examples
htmlhtml-parsingweb-componenthtml5-templatehtml-imports

Does it make sense to declare a doctype for an HTML fragment?


If I have an HTML5 component/WebComponent that has a component.html file that defines a <template>, does it make sense to have a <!DOCTYPE html> declaration in component.html? That is, which of the following is best practice?

<template>
    <!-- some html content -->
</template>

Or

<!DOCTYPE html>
<template>
    <!-- some html content -->
</template>

Solution

  • Both will be parsed and processed the same way in all modern browsers that support the template element.

    One is a few octets lighter!

    So it depends if you prefer speed over strict standards compliance

    Following the KISS principle: The less code I write (and read), the better I feel ;-)