HTML Layout - Using Tables
HTML Layout - Using Tables
Everywhere on the Web you will find pages that are formatted like newspaper pages using HTML
columns.
One very common practice with HTML, is to use An HTML <table> is used to divide a part of this Web
HTML tables to format the layout of an HTML page. page into two columns.
A part of this page is formatted with two columns, The trick is to use a table without borders, and
like a newspaper page. maybe a little extra cell-padding.
As you can see on this page, there is a left column No matter how much text you add to this page, it will
and a right column. stay inside its column borders.
One very common practice with HTML, is to use An HTML <table> is used to divide a part of this Web
HTML tables to format the layout of an HTML page. page into two columns.
A part of this page is formatted with two columns, This text is displayed in the right column.
like a newspaper page.
The trick is to use a table without borders, and
As you can see at this page, there is a left column maybe a little extra cell-padding.
and a right column.
No matter how much text you add to this page, it will
stay inside its column borders.
Examples
Dividing a part of an HTML page into table columns is very easy to do. To let you experiment with it, we
have put together this simple example.
HTML Joke
HTML Frames
With frames, you can display more than one Web page in the same browser window.
Examples
Vertical frameset
This example demonstrates how to make a vertical frameset with three different documents.
Horizontal frameset
This example demonstrates how to make a horizontal frameset with three different documents.
Frames
With frames, you can display more than one HTML document in the same browser window. Each HTML
document is called a frame, and each frame is independent of the others.
• The <frameset> tag defines how to divide the window into frames
• Each frameset defines a set of rows or columns
• The values of the rows/columns indicate the amount of screen area each row/column will occupy
• The <frame> tag defines what HTML document to put into each frame
In the example below we have a frameset with two columns. The first column is set to 25% of the width of
the browser window. The second column is set to 75% of the width of the browser window. The HTML
document "frame_a.htm" is put into the first column, and the HTML document "frame_b.htm" is put into the
second column:
<frameset cols="25%,75%">
<frame src="frame_a.htm">
<frame src="frame_b.htm">
</frameset>
Note: The frameset column size value can also be set in pixels (cols="200,500"), and one of the columns
can be set to use the remaining space (cols="25%,*").
If a frame has visible borders, the user can resize it by dragging the border. To prevent a user from doing
this, you can add noresize="noresize" to the <frame> tag.
Add the <noframes> tag for browsers that do not support frames.
Important: You cannot use the <body></body> tags together with the <frameset></frameset> tags!
However, if you add a <noframes> tag containing some text for browsers that do not support frames, you
will have to enclose the text in <body></body> tags! See how it is done in the first example below.
More Examples
Mixed frameset
This example demonstrates how to make a frameset with three documents, and how to mix them in rows
and columns.
Navigation frame
This example demonstrates how to make a navigation frame. The navigation frame contains a list of links
with the second frame as the target. The file called "tryhtml_contents.htm" contains three links. The source
code of the links:
<a href ="frame_a.htm" target ="showframe">Frame a</a><br>
<a href ="frame_b.htm" target ="showframe">Frame b</a><br>
<a href ="frame_c.htm" target ="showframe">Frame c</a>
The second frame will show the linked document.
Inline frame
This example demonstrates how to create an inline frame (a frame inside an HTML page).
Frame Tags
Tag Description
<frameset> Defines a set of frames
<frame> Defines a sub window (a frame)
<noframes> Defines a noframe section for browsers that do not handle frames
<iframe> Defines an inline sub window (frame)
HTML Fonts
The <font> tag in HTML is deprecated. It is supposed to be removed in a future version of HTML.
Even if a lot of people are using it, you should try to avoid it, and use styles instead.
With HTML code like this, you can specify both the size and the type of the browser output :
<p>
<font size="2" face="Verdana">
This is a paragraph.
</font>
</p>
<p>
<font size="3" face="Times">
This is another paragraph.
</font>
</p>
Try it yourself
Font Attributes
Attribute Example Purpose
size="number" size="2" Defines the font size
size="+number" size="+1" Increases the font size
size="-number" size="-1" Decreases the font size
face="face-name" face="Times" Defines the font-name
color="color-value" color="#eeff00" Defines the font color
color="color-name" color="red" Defines the font color
The <font> tag is deprecated in the latest versions of HTML (HTML 4 and XHTML).
The World Wide Web Consortium (W3C) has removed the <font> tag from its recommendations. In future
versions of HTML, style sheets (CSS) will be used to define the layout and display properties of HTML
elements.
First off: Finish the last chapters in our HTML tutorial !!! In the following chapters we will explain why some
tags, like <font>, are to be removed from the HTML recommendations, and how to insert a style sheet in an
HTML document.
The original HTML was never intended to contain tags for formatting a document. HTML tags were
intended to define the content of the document like:
<p>This is a paragraph</p>
<h1>This is a heading</h1>
When tags like <font> and color attributes were added to the HTML 3.2 specification, it started a
nightmare for web developers. Development of large web sites where fonts and color information had to be
added to every single Web page, became a long, expensive and unduly painful process.
In HTML 4.0 all formatting can be removed from the HTML document and stored in a separate style
sheet.
Because HTML 4.0 separates the presentation from the document structure, we have what we always
needed: Total control of presentation layout without messing up the document content.
Do not use presentation attributes inside your HTML tags if you can avoid it. Start using styles! Please read
our CSS tutorial to learn about style sheets.
Do not use deprecated tags. Visit our complete HTML 4.01 Reference to see which tags and attributes that
are deprecated.
XHTML is the "new" HTML. The most important thing you can do is to start writing valid HTML 4.01. Also
start writing your tags in lower case. Always close your tag elements. Never end a paragraph without </p>.
NOTE: The official HTML 4.01 recommends the use of lower case tags.
If you want to read about how this web site was converted to XHTML, please visit our XHTML tutorial.
Validate Your HTML Files as HTML 4.01
An HTML document is validated against a Document Type Definition (DTD). Before an HTML file can be
properly validated, a correct DTD must be added as the first line of the file.
The HTML 4.01 Strict DTD includes elements and attributes that have not been deprecated or do not appear
in framesets:
The HTML 4.01 Transitional DTD includes everything in the strict DTD plus deprecated elements and
attributes:
The HTML 4.01 Frameset DTD includes everything in the transitional DTD plus frames as well:
HTML Styles
With HTML 4.0 all formatting can be moved out of the HTML document and into a separate style
sheet.
Examples
Styles in HTML
This example demonstrates how to format an HTML document with style information added to the <head>
section.
When a browser reads a style sheet, it will format the document according to it. There are three ways of
inserting a style sheet:
An external style sheet is ideal when the style is applied to many pages. With an external style sheet, you
can change the look of an entire Web site by changing one file. Each page must link to the style sheet using
the <link> tag. The <link> tag goes inside the head section.
<head>
<link rel="stylesheet" type="text/css"
href="mystyle.css">
</head>
An internal style sheet should be used when a single document has a unique style. You define internal styles
in the head section with the <style> tag.
<head>
<style type="text/css">
body {background-color: red}
p {margin-left: 20px}
</style>
</head>
Inline Styles
An inline style should be used when a unique style is to be applied to a single occurrence of an element.
To use inline styles you use the style attribute in the relevant tag. The style attribute can contain any CSS
property. The example shows how to change the color and the left margin of a paragraph:
Style Tags
Tag Description
Joke
Character Entities
Some characters are reserved in HTML. For example, you cannot use the greater than or less than signs
within your text because the browser could mistake them for markup.
If we want the browser to actually display these characters we must insert character entities in the HTML
source.
The advantage of using an entity name instead of a number is that the name often is easier to remember.
However, the disadvantage is that browsers may not support all entity names (while the support for entity
numbers is very good).
Non-breaking Space
Normally HTML will truncate spaces in your text. If you write 10 spaces in your text HTML will remove 9 of
them. To add lots of spaces to your text, use the character entity.
Try It Yourself
This example lets you experiment with character entities: Try it yourself
For a complete reference of all character entities, visit our HTML Entities Reference
HTML Head
Examples
The head element contains general information, also called meta-information, about a document. Meta
means "information about".
You can say that meta-data means information about data, or meta-information means information about
information.
The elements inside the head element should not be displayed by a browser.
According to the HTML standard, only a few tags are legal inside the head section. These are: <base>,
<link>, <meta>, <title>, <style>, and <script>.
<head>
<p>This is some text</p>
</head>
In this case the browser has two options:
If you put an HTML element like <h1> or <p> inside a head element like this, most browsers will display it,
even if it is illegal.
Should browsers forgive you for errors like this? We don't think so. Others do.
Head Tags
Tag Description
<head> Defines information about the document
<title> Defines the document title
<base> Defines a base URL for all the links on a page
<link> Defines a resource reference
<meta> Defines meta information
Tag Description
<!DOCTYPE> Defines the document type. This tag goes before the <html> start tag.
HTML Meta
Examples
Document description
Information inside a meta element describes the document.
Document keywords
Information inside a meta element describes the document's keywords.
Redirect a user
This example demonstrates how to redirect a user if your site address has changed.
As we explained in the previous chapter, the head element contains general information (meta-information)
about a document.
HTML also includes a meta element that goes inside the head element. The purpose of the meta element is
to provide meta-information about the document.
Most often the meta element is used to provide information that is relevant to browsers or search engines
like describing the content of your document.
Note: W3C states that "Some user agents support the use of META to refresh the current page after a
specified number of seconds, with the option of replacing it by a different URI. Authors should not use this
technique to forward users to different pages, as this makes the page inaccessible to some users. Instead,
automatic page forwarding should be done using server-side redirects" at
http://www.w3.org/TR/html4/struct/global.html#adef-http-equiv.
Some search engines on the WWW will use the name and content attributes of the meta tag to index your
pages.
<meta name="description" content="Free Web tutorials on HTML, CSS, XML, and XHTML">
The intention of the name and content attributes is to describe the content of a page.
However, since too many webmasters have used meta tags for spamming, like repeating keywords to give
pages a higher ranking, some search engines have stopped using them entirely.
You can read more about search engines in our Web Building Tutorial.
Sometimes you will see meta attributes that are unknown to you like this:
Then you just have to accept that this is something unique to the site or to the author of the site, and that it
has probably no relevance to you.
You can see a complete list of the meta element attributes in our
Complete HTML 4.01 Tag Reference.
HTML Links
When you click on a link in an HTML document like this: Last Page, an underlying <a> tag points to a place
(an address) on the Web with an href attribute value like this: <a href="lastpage.htm">Last Page</a>.
The Last Page link in the example is a link that is relative to the Web site that you are browsing, and your
browser will construct a full Web address like http://www.w3schools.com/html/lastpage.htm to access the
page.
scheme://host.domain:port/path/filename
The scheme is defining the type of Internet service. The most common type is http.
The host is defining the domain host. If omitted, the default host for http is www.
The :port is defining the port number at the host. The port number is normally omitted. The default port
number for http is 80.
The path is defining a path (a sub directory) at the server. If the path is omitted, the resource (the
document) must be located at the root directory of the Web site.
The filename is defining the name of a document. The default filename might be default.asp, or index.html
or something else depending on the settings of the Web server.
URL Schemes
Schemes Access
file a file on your local PC
ftp a file on an FTP server
http a file on a World Wide Web Server
gopher a file on a Gopher server
news a Usenet newsgroup
telnet a Telnet connection
WAIS a file on a WAIS server
Accessing a Newsgroup
<a href="mailto:[email protected]">[email protected]</a>
HTML Scripts
Add scripts to HTML pages to make them more dynamic and interactive.
Examples
Insert a script
This example demonstrates how to insert a script into your HTML document.
A script in HTML is defined with the <script> tag. Note that you will have to use the type attribute to specify
the scripting language.
<html>
<head>
</head>
<body>
<script type="text/javascript">
document.write("Hello World!")
</script>
</body>
</html>
Hello World!
Note: To learn more about scripting in HTML, visit our JavaScript School.
Example
JavaScript:
<script type="text/javascript">
<!--
document.write("Hello World!")
//-->
</script>
VBScript:
<script type="text/vbscript">
<!--
document.write("Hello World!")
'-->
</script>
In addition to hiding the script inside a comment, you can also add a <noscript> tag.
The <noscript> tag is used to define an alternate text if a script is NOT executed. This tag is used for
browsers that recognize the <script> tag, but do not support the script inside, so these browsers will display
the text inside the <noscript> tag instead. However, if a browser supports the script inside the <script> tag
it will ignore the <noscript> tag.
Example
JavaScript:
<script type="text/javascript">
<!--
document.write("Hello World!")
//-->
</script>
<noscript>Your browser does not support JavaScript!</noscript>
VBScript:
<script type="text/vbscript">
<!--
document.write("Hello World!")
'-->
</script>
<noscript>Your browser does not support VBScript!</noscript>
Script Tags
Tag Description
<script> Defines a script
HTML tags can have attributes. The special attributes for each tag are listed under each tag description. The
attributes listed here are the core and language attributes that are standard for all tags (with a few
exceptions):
Core Attributes
Not valid in base, head, html, meta, param, script, style, and title elements.
Language Attributes
Not valid in base, br, frame, frameset, hr, iframe, param, and script elements.
Keyboard Attributes
Attribute Value Description
accesskey character Sets a keyboard shortcut to access an element
tabindex number Sets the tab order of an element
If you want to learn more about programming with these events, you should study our JavaScript tutorial
and our DHTML tutorial.
Window Events
Keyboard Events
Not valid in base, bdo, br, frame, frameset, head, html, iframe, meta, param, script, style, and title
elements.
Mouse Events
Not valid in base, bdo, br, frame, frameset, head, html, iframe, meta, param, script, style, title elements.
URL encoding converts characters into a format that can be safely transmitted over the Internet.
URL Encoding
URLs can only be sent over the Internet using the ASCII character-set.
Since URLs often contains characters outside the ASCII set, the URL has to be converted. URL encoding
converts the URL into a valid ASCII format.
URL encoding replaces unsafe ASCII characters with "%" followed by two hexadecimal digits corresponding
to the character values in the ISO-8859-1 character-set.
URLs cannot contain spaces. URL encoding normally replaces a space with a + sign.
Try It Yourself
If you click the "Submit" button below, the browser will URL encode the input before it is sent to the server.
A page at the server will display the received input.
Submit
For a complete reference of all URL encodings, visit our URL Encoding Reference.
• If you want other people to view your pages, you must publish them.
• To publish your work, you must save your pages on a web server.
• Your own PC can act as a web server if you install IIS or PWS.
• IIS or PWS turns your computer into a web server.
• Microsoft IIS and PWS are free web server components.
IIS is for Windows system like Windows 2000, XP, and Vista. It is also available for Windows NT.
IIS is easy to install and ideal for developing and testing web applications.
IIS includes Active Server Pages (ASP), a server-side scripting standard that can be used to create dynamic
and interactive web applications.
If you want to read more about ASP, you should study our ASP School.
PWS is for older Windows system like Windows 95, 98, and NT.
PWS is easy to install and can be used for developing and testing web applications including ASP.
We don't recommend running PWS for anything else than training. It is outdated and have security issues.
Follow these steps to install IIS on Windows XP, and Windows 2000:
After you have installed IIS, make sure you install all patches for bugs and security problems. (Run Windows
Update).
Note: Look for the IIS (or PWS) symbol in your start menu or task bar. The program has functions for
starting and stopping the web server, disable and enable ASP, and much more.
For Windows 98: Open the Add-ons folder on your Windows CD, find the PWS folder and run setup.exe to
install PWS.
For Windows 95 or Windows NT: Download "Windows NT 4.0 Option Pack" from Microsoft, and install PWS.
• If you do not want to use PWS or IIS, you must upload your files to a public server.
• Most Internet Service Providers (ISP's) will offer to host your web pages.
• If your employer has an Internet Server, you can ask him to host your Web site.
• If you are really serious about this, you should install your own Internet Server.
Before you select an ISP, make sure you read W3Schools Web Hosting Tutorial !!
You Have Learned HTML, Now What?
HTML Summary
This tutorial has taught you how to use HTML to create your own web site.
HTML is the universal markup language for the Web. HTML lets you format text, add graphics, create links,
input forms, frames and tables, etc., and save it all in a text file that any browser can read and display.
The key to HTML is the tags, which indicates what content is coming up.
For more information on HTML, please take a look at our HTML examples and our HTML reference.
XHTML
If you want to learn more about XHTML, please visit our XHTML tutorial.
CSS
CSS is used to control the style and layout of multiple Web pages all at once.
With CSS, all formatting can be removed from the HTML document and stored in a separate file.
CSS gives you total control of the layout, without messing up the document content.
To learn how to create style sheets, please visit our CSS tutorial.
The perfect solution for busy professionals who need to balance work, family, and
career building.
The HTML Certificate documents your knowledge of HTML, XHTML, and CSS.
The JavaScript Certificate documents your knowledge of JavaScript and the HTML DOM.
The XML Certificate documents your knowledge of XML, XML DOM and XSLT.
The ASP Certificate documents your knowledge of ASP, SQL, and ADO.
The PHP Certificate documents your knowledge of PHP and SQL (MySQL).