2.3 - 2.4 Beginning

posted July 11, 2015

2.3 <!DOCTYPE>

<!DOCTYPE html>means that the page is written in HTML5.

Every web page should have a doctype declaration, it a requirement.1

The<!DOCTYPE> declaration must be the first thing in your HTML document, before the <html> tag.

The <!DOCTYPE> declaration is not an HTML tag; it is an instruction to the web browser about what version of HTML the page is written in.

The official HTML documentation capitalizes the doctype, like the snippet below, however, it is HTML5 is case insensitive so you can also write it in lowercase.

2.4 <!-- comments -->

Comments are inserted into your source code but are not viewable to the user.

Comments can be useful for developers, leaving notes for themselves or future developers.

<!-- This is a comment -->

<p>This is a paragraph.</p>

<!-- Comments are not displayed in the browser -->
            

Notes and Resources

  1. DOCTYPEs are required for legacy reasons. When omitted, browsers tend to use a different rendering mode that is incompatible with some specifications. Including the DOCTYPE in a document ensures that the browser makes a best-effort attempt at following the relevant specifications. (W3C)

    .