the absolute minimum is defined as:
An HTML 4 document is composed of three parts:or expressed in code:
- a line containing HTML version information,
- a declarative header section (delimited by the HEAD element),
- a body, which contains the document's actual content. The body may be implemented by the BODY element or the FRAMESET element.
Expand|Select|Wrap|Line Numbers
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
- "http://www.w3.org/TR/html4/strict.dtd">
- <HTML>
- <HEAD>
- <TITLE>My first HTML document</TITLE>
- </HEAD>
- <BODY>
- </BODY>
- </HTML>
From my experiences there is at least one additional element, you absolutely should use: the "content-type" meta element.
Not only does it provide the browser with the HTML MIME type, it also tells it about the used character encoding (while this may be of no concern to english content, it is a concern to anyone whose language uses more than the ASCII characters (e.g. Chinese, Japanese and other Asian languages, European languages (nearly every european language besides English and Italian, e.g. French (é, à, û, ç), German (ä, ö, ü, ß), etc.), Languages using cyrillic (and related) characters (e.g. Russian), Arabic languages and many more). And there is usually more than one character set for a language…
OK, back to topic. This is the HTML template that I use for coding (variables in curly braces)
Expand|Select|Wrap|Line Numbers
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
- <html lang="{en}">
- <head>
- <meta http-equiv="content-type" content="text/html;charset={utf-8}">
- <title>{your page title}</title>
- <link rel="stylesheet" href="{your.css}" media="screen">
- <style type="text/css">
- {your CSS definitions}
- </style>
- <script type="text/javascript" src="{your.js}"></script>
- <script type="text/javascript">
- {your JavaScript code}
- </script>
- </head>
- <body>
- </body>
- </html>
- some earlier browsers required the script content to be wrapped in comment tags (<!-- -->), so that the content is not displayed. Any decent browser nowadays knows the difference between <head> and <body>, so this is not necessary anymore.
- HTML element names may be written upper or lower case. However, I recommend lower case.
Of course there is another upcoming HTML variant: XHTML. before I get to the code, one word of caution: Internet Explorer does not support native XHTML (there are some hacks, though)
however, since XHTML is a subset of XML, it is recommended to us an XHTML Media Type (probably due to the compatibility issues (mainly with IE)), which is "application/xhtml+xml".
IMPORTANT: if you serve your XHTML with the "text/html" mediatype, it is not treated as XHTML at all. It is then processed as HTML, which makes the effort of writing XHTML futile.
Naturally, there are also requirements for XHTML (including a HTML/XHTML comparison).
This is my XHTML template, which is not intended to be HTML compatible (in the first place), thus using the somewhat more restrictive XHTML 1.1 subset. (To serve these files to IE, I use a server script to transform it into HTML.)
Expand|Select|Wrap|Line Numbers
- <?xml version="1.0" encoding="{ISO-8859-1}" ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{en}">
- <head>
- <meta http-equiv="content-type" content="application/xhtml+xml;charset={ISO-8859-1}"/>
- <title>{your page title}</title>
- <link rel="stylesheet" href="{your.css}" media="screen"/>
- <style type="text/css">
- /* <![CDATA[ */
- {your CSS definitions}
- /* ]]> */
- </style>
- <script type="text/javascript" src="{your.js}"></script>
- <script type="text/javascript">
- // <![CDATA[
- {your JavaScript code}
- // ]]>
- </script>
- </head>
- <body>
- </body>
- </html>
- in contrast to HTML, XHTML files are checked for validaty by the browser (the XML parser, to be exact). If your document is neither well-formed nor valid (or both), you are prompted with an error message.
- if—and only if—you use the UTF-8 or UTF-16 charset, you may omit the XML prolog (it’s the default encoding)
- using " />" (with a leading space) for the empty element tag should be used when you’re writing HTML compatible XHTML*.
- XHTML element names must be written in lower case.
- the CDATA sections in <script> and <style> are required to keep the document valid**.
- the <body> element itself does not allow for plain text and inline elements***.
** due to XML restrictions
*** as defined in the DTD
thanks for your attention so far and happy copy/paste
PS don’t forget to save the document in that encoding you defined in the document.