Write a comment on this article
HTML (Hypertext markup language) is a markup language, but not a programming language because there are neither operations, variables or functions nor methods or classes. It describes where and how content is placed on a website and allows only little interactions with the user.
Basically, HTML consists of many different elements which look like this:
<myelement color="red" width="100">hello world</myelement>
As you can see, an element consists of a three parts: an opening tag, inner text and a closing tag (same element name with a leading slash). The opening tag defines the element more precisely. It contains the name ("myelement"), attributes ("color", "width") and attribute values ("red", "100"). Sometimes, attributes, the inner text and the closing tag may be omitted, like in this example.
<br>
The element <br> is a linebreak and has neither attributes nor an inner text or a closing tag. The available elements and their attributes are defined in the document type which is specified by the World Wide Web consortium. More about the document type later on.
HTML always follows a basic structure. First, you need to declare which document type is used in your page. Afterwards you define the header which contains the title, meta information and scripts. Finally, you write the body of your page which will be visible in the browser. Mostly, the body is the biggest part as it contains all contents of your page. Here is a short example:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
...
</head>
<body>
...
</body>
</html>
The header (everything between <head> and </head>) contains the title of the page, meta information (like information about the author, this information is often used by search engines), links to other resources and scripts which allow the integration of specific programming languages. The following example contains the document title, meta information (keywords and description) and two references to a JavaScript file and a CSS file.
<head> <title>My page</title> <meta name="keywords" content="games,movies,music"> <meta name="description" content="My page about games, movies and music"> <link rel="stylesheet" type="text/css" href="my_stylesheet.css"> <script type="text/javascript" src="my_javascript.js"></script> </head>
A special page type is a frameset. A frameset displays other HTML pages on one page in different frames and doesn't contain a body itself (it is possible to insert content which is only displayed when the browser doesn't support frames). So, a frameset is, as the name tells, a set of frames and is defined outside the header. Here is a short example (you can try it here: frameset.html):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<title>My page</title>
</head>
<frameset cols="150,*">
<frameset rows="20%,80%">
<frame src="frameset_logo.html">
<frame src="frameset_menu.html">
</frameset>
<frame src="frameset_home.html">
<noframes>
<p>This page contains a frameset but your browser does not support frames.</p>
<ul>
<li><a href="frameset_logo.html">Logo</a></li>
<li><a href="frameset_menu.html">Menu</a></li>
<li><a href="frameset_home.html">Homepage</a></li>
</ul>
</noframes>
</frameset>
</html>
This example will result in the following output:

Let's take a closer look on the document type. The document type is defined at the very beginning of a page and describes which elements and attributes are allowed. There are three different types: Transitional, Strict and Frameset. Here is an overview of these types (for an exact list which elements are allowed in which document types please check the resources and links below).
This document type includes all elements and attributes specified in the used HTML version (e.g. HTML 4.0, HTML 4.01, XHTML 1.0, etc.) except frame-related elements (frameset, frame, noframes). It also includes deprecated elements. "Deprecated" means that these elements will be removed in future versions and should not be used anymore, like the element center in HTML 4.01. Here is a short list of allowed elements in HTML 4.01:
a, applet, b, body, br, button, center, dd, div, dl, dt, font, form, h1 - h6, head, hr, html, iframe, img, input, label, map, option, p, pre, script, select, span, strong, style, table, td, textarea, tr, u
This document type includes all elements and attributes as Transitional except the deprecated ones. In this case, "strict" means to focus more on structuring a document than on styling. Here are some elements which are not allowed in HTML 4.01 Strict:
applet, basefont, center, dir, font, iframe, isindex, menu, s, strike, u
As the name tells this document type includes all frame-related elements. Also, all elements from Transitional are included, so this is the most generous document type. The following elements are additionally available:
frameset, frame, noframes
It is your job to choose the correct document type for your page, although browsers are very tolerant if you accidentally choose the wrong one. You also need to decide which HTML version you are going to use - the most common one are HTML 4.01 and XHTML 1.0. XHTML is based on XML and follows it's rules. This means XHTML documents need to be valid and well-formed. This includes some rules like writing element and attribute names lowercase, closing all opened tags, etc.
The body (everything between <body> and </body>) contains all contents of your page: texts, images, links, forms, tables and so on. In the table below you can find the most important elements to be used in the body.
| Element | Description | Important attributes | Example (HTML 4.01 Transitional) |
| a | A link to another resource, e.g. an HTML document or an image. The Url of the resource is specified in the attribute "href". The inner part (text, image) of the element will be clickable. | href target title |
<a href="another_document.html" target="_blank" title="Another document">Click here</a> |
| br | Forces a line break in a text. | This is line one.<br>This is line two. | |
| div | Adds block-level structure to documents. | <div>This is block one.</div> <div>This is block two.</div> |
|
| form | A collection of input fields (textares, radiobuttons, checkboxes, ...) to submit data (text and files). | action enctype method |
<form action="another_document.html" enctype="text/plain" method="post">here go the input fields</form> |
| h1 | Defines a heading. h2 - h6 are subheadings and differ in font-size and font-style. | <h1>This is heading 1</h1> <h2>This is a subheading</h2> |
|
| img | Displays an image. The Url of the image is specified in the attribute "href". | alt border height src title width |
<img alt="Image of an elephant" border="0" height="600" src="elephant.jpg" title="This is my lovely elephant" width="800"> |
| input | An element in a form to input text, submit a form, select a radiobutton or checkbox, reset a form, select a file or input a password. | checked maxlength name type value |
<input maxlength="255" name="lastname" type="text" value="Please input your lastname year"> |
| option | An item of a select-list. Consists of a text and a value. | selected value |
<select name="favorite_color"> <option value="0_blue">blue</option> <option value="1_yellow">yellow</option> <option value="2_red">red</option> </select> |
| p | A paragraph. Note that there may not be a paragraph inside a paragraph. | <p>This is paragraph one.</p> <p>This is paragraph two.</p> |
|
| select | A select-list containing several options. One or more options can be selected. | multiple name size |
<select name="favorite_colors" size="2" multiple> <option value="0_blue">blue</option> <option value="1_yellow">yellow</option> <option value="2_red">red</option> </select> |
| table | Defines a container for table. This container contains rows, columns and cells. | border cellpadding cellspacing width |
<table border="0" cellpadding="2" cellspacing="3" width="100%">here goes the table content</table> |
| td | A table cell containing table data. | colspan rowspan valign width |
<td colspan="2" rowspan="3" valign="top" width="100">cell content</td> |
| textarea | A multi-line text input field. Content is defined by inner text. Adds scrollbars if text is too long. | cols name rows |
<textarea cols="40" name="user_description" rows="10">here goes the default value</textarea> |
| tr | Defines a container for a row of a table. | <table> <tr> here go the table cells </tr> </table> |
With this knowledge you are ready to build any HTML file. There is one more thing you should know when writing HTML files: comments. Comments are enclosed by special tags (<!-- and -->) and are ignored by the browser. Here is a short example:
<p>This is paragraph one.</p> <!-- This is a comment and will not be interpreted by the browser. --> <p>This is paragraph two.</p>
HTML, introduction, document type, frameset, elements, tags, comments
If you have a question or a problem and you're looking for a solution, please use the forum. Comments might not be answered.