HyperText Markup Language
HTML was and is still used to layout pages, however this practice is outdated, and is only making the html harder to maintain. Most attributes and elements used for presentation has been deprecated, meaning that they should generally be avoided in favor for the better alternatives. HTML is widely used together with CSS to separate as much content from style as possible, and to make it easier to make layout related changes.
CSS dose not only make it easier to maintain a website, it also makes it easier to create the website.
Demonstration
The below is a simple example, using the strict Doctype of HTML 4.01. The "lang" attribute on the html tag helps search engines, and user agents to determine the language on your site, the attribute is required for your code to validate.
<html lang="en">
<head>
The Doctype Declaration
Browsers will by default render websites in backwards compatibility mode, aka quirks mode. That is unless it manages to find a valid doctype declaration. The browser goes into standards mode if a doctype is found, and this is to prefer since web designers otherwise may not be able to get their pages to render equally in all browsers.
The HTML Doctypes
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
The XHTML Doctypes
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
The Transitional, frameset and Strict Doctypes
The Transitional doctype is used when you want to include deprecated elements and attributes, while the strict doctype closer reflects current recommendations, those may be anything from usage of certain tags, to individual attributes. Although lists of deprecated attributes and elements exists, its more or less pointless to list those, and better to keep an eye on current and new recommendations.
The frameset doctypes are used for pages which contain frames. Also note that the XHTML1.1 Doctype is different from the other XHTML doctypes, in that the other doctypes allowed for more presentational components.
Validation
While validation is important, experianced web designers might chose to leave out the validation process to save time, also note that many errors may be intended and non-fetal to the rendering of a page.
Elements
Attributes
Attributes in html are written by their name in the opening tag, followed by the equal sign "=" and a quoted or unquated value, it is recommended that you always quote your attribute values. Some of the more common attributes today are listed below.
- class
- id
- alt
- title
- src
- href
For a full list, you should check the reference entry HTML Attributes at Brugbart.
The class Attribute
This attribute is used to "group" elements. Used in conjuction with css, this may be used to easily apply styling to groups of elements, example follows.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>Usage of the class attribute</title>
<style type="text/css">
.Blue {
color: blue;
}
.Purple {
color: blue;
}
</style>
</head>
<body>
<h1>Usage of the class attribute.</h1>
<p class="Blue">This paragraph is written in blue.</p>
<p><a href="http://www.brugbart.com/" class="Blue">Tutorials/References</a></p>
<p><a href="http://validator.w3.org/" class="Purple">The W3C Markup Validation Service</a></p>
</body>
</html>
The id Attribute
The id attribute is similar to the class attribute, the important differance is that a given id must not be repeated, since id is used for unique identification. The number sign is used when dealing with id selectors, see below:
<style type="text/css">
#Blue {
color: blue;
}
#Purple {
color: blue;
}
</style>
Note. Ids must begin with a letter, using numbers will throw out an error when validating.
The attribute is also used when linking to sections in a document, the Number sign "#" is used at the end of URLs, followed by the id of the element linked to, this is usually the headlines (h1-h6), see below:
<body>
<h1 id="Section1">The id attribute Explained.</h1>
<p class="Blue">The id attribute is used for unique identification.</p>
<h2 id="Section2">Subsection.</h2>
<p class="Blue">This is just a demonstration.</p>
</body>
The above sections can be linked to by entering the normal URL I.E. index.html followed by the number sign "#" and the id, full URL would be index.html#Section2, note that this can also be combined with URL parameters, the id would simply be placed after any URL parameters. In case of linking to a section in the main page, it might be better to simply type /#Section2, which uses a root relative path, See also: Absolute and Relative Paths.
The alt Attribute
This attribute is used to display alternative text for Screen Readers, and devices with less functionality such as handheld devices. It may also be useful for people who have limited brandwidth, since those may on a rare occasion disable loading of graphics. It would also be useful for people who have disabled flash.
Finally the alt attribute may be of some use to search engines, since those won't understand information displayed in I.E. Images.
<body>
<h1 id="Section1">Alt Attribute Example.</h1>
<p><img src="MyImage.png" alt="Example Image"></p>
</body>
The title Attribute
<h1 id="Section1">Title Attribute Example.</h1>
<p><a href="http://www.brugbart.com/" title="Learn By Doing - Brugbart.com">Tutorials/References.</a></p>
</body>
The src Attribute
The src Attribute stands for "source" and is used on img elements, to link to an image.
<body>
<p><img src="images/yourimage.png" alt="An Image"></p>
</body>
Images must be inclosed in other block level elements, I.E. paragraphs.
The href Attribute
The href attribute is used to link to resources such as StyleSheets, or favicons. Even other documents and websites, the destination of the anchor is defined with a URI.
<head>
<!-- resources -->
<link rel="shortcut icon" href="/favicon.ico">
<link href="/templates/Blue.css" rel="stylesheet" type="text/css">
</head>
<body>
<!-- Links -->
<p>Follow <a href="http://www.brugbart.com/">This Link</a> to visit my website.</p>
</body>
HTML vs XHTML
There are few benefits from using XHTML, generally most users wont benefit from using XHTML. The main benefit from using XHTML, is that you can mix XHTML with other XML based languages, such as SMIL or SVG. If you are just using XHTML alone, then you might as well simply use HTML4.01 Strict. More info at: http://www.w3.org/MarkUp/2004/xhtml-faq#advantages
Releted Knols
- CSS - Cascading Style Sheets Tutorial/Knol
Links
- Brugbarts HTML Reference
- The W3C Markup Validation Service - Used to check code for errors.






Comments
Write New Comment ▼
Write New Comment
Sorry! This knol's owner(s) have blocked you from editing, making suggestions, or commenting here.