Sabado, Hulyo 9, 2011
MINIMAL HTML DOCUMENT
Every HTML 3.2 document must also include the descriptive title element. At the time HTML 3.2 was the recommended spec, very few web designers bothered with a DOCTYPE, or with valid code at all, so in practice an HTML document could be any text file containing any combination of text and HTML tags.
These days, the needs of accessibility, search engine optimization, document consistency for JavaScript manipulation, and support for international characters all combine to require more of our HTML. The minimal HTML document has gotten a lot bigger.
The Breakdown
Every (X)HTML document should start with a DOCTYPE declaration that tells the browser what version of (X)HTML the document is written in. In practical terms, this tells browsers like Internet Explorer and Firefox to use their most standards-compliant (and therefore cross-browser-compatible) rendering mode.
Next, we mark the start of the document with the opening html tag. This tag should should specify the primary language for the document’s content, with the lang attribute.
In an XHTML document, you should also specify the document’s default XML namespace (using the xmlns attribute) and re-specify the language using XML’s standard xml:lang attribute.
Next comes the head tag, which starts the document header.
The first thing in the header should be a meta tag that specifies the character encoding of the page. Usually, the character encoding is declared by the web server that sends the page to the browser, but many servers are not configured to send this information, and specifying it here ensures the document is displayed correctly even when it is loaded directly from disk, without consulting a server.
In an XHTML document, meta tags should end with a slash to indicate they are empty.
With the encoding established, we can safely write the first piece of actual content in the page—the page title.
If you want to link a CSS file to the page to control its appearance (which you usually will), a link tag at this point will do the trick:
Again, the XHTML version of this tag needs a trailing slash to indicate it is empty.
If you want to link a JavaScript script to the page, and the script is designed to be invoked from the header, insert a script tag at this point. Whether the document is HTML or XHTML, you should include a full script closing tag for backwards compatibility.
That just about does it. You can end the header, then start the body of the page with a body tag. The content of the page is up to you, but since we’re talking about a minimal document, there need not be any body content at all.
So, how does your most recent work hold up? Have you included all the elements discussed above? Common omissions like the lang attribute and the content-type meta tag may seem unnecessary, but they really put that final layer of polish that ensure your site holds up with the best on the Web.
Mag-subscribe sa:
I-post ang Mga Komento (Atom)
Walang komento:
Mag-post ng isang Komento