Example Explained: K 9 Computer Labs
Example Explained: K 9 Computer Labs
Example Explained: K 9 Computer Labs
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
Example Explained
The text between <html> and </html> describes the web page
The text between <body> and </body> is the visible page content
What is HTML?
HTML is a language for describing web pages.
HTML Tags
HTML markup tags are usually called HTML tags.
HTML tags are keywords (tag names) surrounded by angle brackets like <html>
The first tag in a pair is the start tag, the second tag is the end tag
[K 9 COMPUTER LABS]
The end tag is written like the start tag, with a slash before the tag name
Start and end tags are also called opening tags and closing tags
<tagname>content</tagname>
HTML Elements
In HTML, most elements are written with a start tag (e.g. <p>) and an end tag (e.g. </p>), with the content in between:
<p>This is a paragraph.</p>
Web Browsers
The purpose of a web browser (such as Google Chrome, Internet Explorer, Firefox, Safari) is to read HTML documents
and display them as web pages.
The browser does not display the HTML tags, but uses the tags to determine how the content of the HTML page is to be
presented/displayed to the user:
[K 9 COMPUTER LABS]
HTML Versions
Since the early days of the web, there have been many versions of HTML:
Version
HTML
HTML+
HTML 2.0
HTML 3.2
HTML 4.01
XHTML
HTML5
Year
1991
1993
1995
1997
1999
2000
2012
Common Declarations
HTML5
<!DOCTYPE html>
[K 9 COMPUTER LABS]
HTML 4.01
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
XHTML 1.0
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
HTML Editors
Write HTML Using Notepad or TextEdit
HTML can be edited by using a professional HTML editor like:
Adobe Dreamweaver
However, for learning HTML we recommend a text editor like Notepad (PC) or TextEdit (Mac).
We believe using a simple text editor is a good way to learn HTML.
Follow the 4 steps below to create your first web page with Notepad.
Example
<!DOCTYPE html>
<html>
<body>
[K 9 COMPUTER LABS]
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
HTML Headings
HTML headings are defined with the <h1> to <h6> tags.
[K 9 COMPUTER LABS]
Example
<h1>This is a heading</h1>
<h2>This is a heading</h2>
<h3>This is a heading</h3>
HTML Paragraphs
HTML paragraphs are defined with the <p> tag.
Example
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
HTML Links
HTML links are defined with the <a> tag.
Example
<a href="http://www.k9computerlabs.com">This is a link</a>
HTML Images
HTML images are defined with the <img> tag.
Example
<img src="k9image.jpg" alt="k9image.com" width="104" height="142">
Note: The filename and the size of the image are provided as attributes.
[K 9 COMPUTER LABS]
<p>This is a paragraph
<p>This is a paragraph
The example above works in most browsers, because the closing tag is considered optional.
Never rely on this. Many HTML elements will produce unexpected results and/or errors if you forget the end tag .
[K 9 COMPUTER LABS]
Hello
You delivered your assignment ontime.
Thanks
Mahnaz
Centering Content
You can use <center> tag to put any content in the center of the page or any table cell.
Example
<!DOCTYPE html>
<html>
<head>
<title>Centring Content Example</title>
</head>
<body>
<p>This text is not in the center.</p>
<center>
<p>This text is in the center.</p>
</center>
</body>
</html>
Horizontal Lines
Horizontal lines are used to visually break up sections of a document. The <hr> tag creates a line from the current
position in the document to the right margin and breaks the line accordingly.
For example you may want to give a line between two paragraphs as in the given example below:
Example
<!DOCTYPE html>
<html>
<head>
<title>Horizontal Line Example</title>
</head>
<body>
<p>This is paragraph one and should be on top</p>
<hr />
<p>This is paragraph two and should be at bottom</p>
</body>
</html>
[K 9 COMPUTER LABS]
Again <hr /> tag is an example of the empty element, where you do not need opening and closing tags, as there is nothing
to go in between them.
The <hr /> element has a space between the characters hr and the forward slash. If you omit this space, older browsers
will have trouble rendering the horizontak line, while if you miss the forward slash character and just use <hr> it is not
valid in XHTML
Attributes provide additional information about HTML elements.
HTML Attributes
Attribute Example
HTML links are defined with the <a> tag. The link address is specified in the href attribute:
Example
<a href="http://www.k9computerlabs.com">This is a link</a>
[K 9 COMPUTER LABS]
However, the World Wide Web Consortium (W3C) recommends lowercase attributes/attribute values in their HTML 4
recommendation.
Newer versions of (X)HTML will demand lowercase attributes.
Description
class
Specifies one or more classnames for an element (refers to a class in a style sheet)
id
style
title
For more information about global attributes: HTML Global Attributes Reference.
Note: Browsers automatically add some empty space (a margin) before and after each heading.
[K 9 COMPUTER LABS]
The browser will remove extra spaces and extra lines when the page is displayed. Any number of lines count as one line,
and any number of spaces count as one space.
<!DOCTYPE html>
<html>
<body>
<p>
My Bonnie lies over the ocean.
<p>Note that your browser ignores the layout in the HTML source code!</p>
</body>
</html>
My Bonnie lies over the ocean. My Bonnie lies over the sea. My Bonnie lies over the ocean. Oh, bring back my Bonnie to
me.
Note that your browser ignores the layout in the HTML source code!
[K 9 COMPUTER LABS]
superscript
[K 9 COMPUTER LABS]
<strong> or <em> means that you want the text to be rendered in a way that the user understands
as "important". Today, all major browsers render strong as bold and em as italics. However, if a
browser one day wants to make a text highlighted with the strong feature, it might be cursive for
example and not bold!
Description
<b>
<em>
<i>
<small>
<sup>
<ins>
<del>
<mark>
#Practice
HTML <ins> Tag
Example
A text with a deleted part, and a new, inserted part:
<p>My favorite color is <del>blue</del> <ins>red</ins>!</p>
<!DOCTYPE html>
<html>
<body>
[K 9 COMPUTER LABS]
</body>
</html>
#Practice
HTML <del> Tag
Example
A text with a deleted part, and a new, inserted part:
<p>My favorite color is <del>blue</del> <ins>red</ins>!</p>
</body>
</html>
[K 9 COMPUTER LABS]
#Practice
HTML <mark> Tag
Example
Highlight parts of a text:
<p>Do not forget to buy <mark>milk</mark> today.</p>
[K 9 COMPUTER LABS]
<p>Do not forget to buy <mark>milk</mark> today.</p>
</body>
</html>
Description
<code
Defines computer code text
>
<kbd> Defines keyboard text
<sam Defines sample computer
p>
code
<var> Defines a variable
<pre> Defines preformatted text
<!DOCTYPE html>
<html>
<body>
<em>Emphasized text</em><br>
<strong>Strong text</strong><br>
<dfn>Definition term</dfn><br>
<code>A piece of computer code</code><br>
<samp>Sample output from a computer program</samp><br>
<kbd>Keyboard input</kbd><br>
<var>Variable</var>
</body>
</html>
[K 9 COMPUTER LABS]
<!DOCTYPE html>
<html>
<body>
<pre>
Text in a pre element
is displayed in a fixed-width
font, and it preserves
both
spaces and
line breaks
</pre>
</body>
</html>
Description
<abbr>
<address>
<bdo>
<blockquote
Defines a section that is quoted from another source
>
<q>
<cite>
<dfn>
[K 9 COMPUTER LABS]
#Practice
HTML <abbr> Tag
Example
An abbreviation is marked up as follows:
The <abbr title="World Health Organization">WHO</abbr> was founded in 1948.
<!DOCTYPE html>
<html>
<body>
</body>
</html>
#Practice
HTML <address> Tag
[K 9 COMPUTER LABS]
Example
Contact information for Example.com:
<!DOCTYPE html>
<html>
<body>
<address>
Written by <a href="mailto:webmaster@example.com">Jon Doe</a>.<br>
Visit us at:<br>
Example.com<br>
Box 564, Disneyland<br>
USA
</address>
</body>
</html>
#Practice
HTML <bdo> Tag
Example
[K 9 COMPUTER LABS]
Specify the text direction:
<!DOCTYPE html>
<html>
<body>
<p>This paragraph will go left-to-right.</p>
<p><bdo dir="rtl">This paragraph will go right-to-left.</bdo></p>
</body>
</html>
#Practice
HTML <blockquote> Tag
Example
A section that is quoted from another source:
<blockquote cite="http://www.worldwildlife.org/who/index.html">
For 50 years, WWF has been protecting the future of nature. The world's leading conservation organization, WWF works
in 100 countries and is supported by 1.2 million members in the United States and close to 5 million globally.
</blockquote>
<!DOCTYPE html>
<html>
<body>
<h1>About WWF</h1>
<p>Here is a quote from WWF's website:</p>
<blockquote cite="http://www.worldwildlife.org/who/index.html">
For 50 years, WWF has been protecting the future of nature. The world's leading conservation organization,
WWF works in 100 countries and is supported by 1.2 million members in the United States and close to 5
million globally.
</blockquote>
[K 9 COMPUTER LABS]
</body>
</html>
Example
Mark up a short quotation:
</body>
</html>
[K 9 COMPUTER LABS]
<img src="img_the_scream.jpg" width="220" height="277" alt="The Scream">
<p><cite>The Scream</cite> by Edward Munch. Painted in 1893.</p>
</body>
</html>
Comments are not displayed by the browser, but they can help document your HTML.
With comments you can place notifications and reminders in your HTML:
Example
<!-- This is a comment -->
<p>This is a paragraph.</p>
<!-- Remember to add more information here -->
Comments are also great for debugging HTML, because you can comment out HTML lines of code, one at a time, to
search for errors:
Example
<!-- Do not display this at the moment
<img border="0" src="/images/pulpit.jpg" alt="Pulpit rock" width="304" height="228">
-->
Conditional Comments
You might stumble upon conditional comments in HTML:
<!--[if IE 8]>
.... some HTML here ....
<![endif]-->
Conditional comments defines HTML tags to be executed by IE only. We will not use conditional comments here.
[K 9 COMPUTER LABS]
Example
<a href="http://www.k9computerlabs.com/">Visit k9computerlabs </a>
[K 9 COMPUTER LABS]
Example
<a href="http://www.k9computerlabs.com/" target="_blank">Visit k9computerlabs!</a>
Example
An anchor with an id inside an HTML document:
<a id="tips">Useful Tips Section</a>
Create a link to the "Useful Tips Section" inside the same document:
<a href="#tips">Visit the Useful Tips Section</a>
Or, create a link to the "Useful Tips Section" from another page:
<a href="http://www. k9computerlabs.com/html_links.htm#tips">
Visit the Useful Tips Section</a>
[K 9 COMPUTER LABS]
The <title> tag defines the title of the document.
The <title> element is required in all HTML/XHTML documents.
The <title> element:
[K 9 COMPUTER LABS]
<head>
<style type="text/css">
body {background-color:yellow;}
p {color:blue;}
</style>
</head>
[K 9 COMPUTER LABS]
Description
<head>
<title>
<base>
<link>
<meta>
<script>
<style>
[K 9 COMPUTER LABS]
Look! Styles and colors
M a n i p u l a t e
C o l o r s ,
T e x t
B o x e s
and more...
The preferred way to add CSS to HTML, is to put CSS syntax in separate CSS files.
However, in this HTML study material we will introduce you to CSS using the style attribute. This is done to simplify the
examples.
Inline Styles
An inline style can be used if a unique style is to be applied to one single occurrence of an element.
To use inline styles, use the style attribute in the relevant tag. The style attribute can contain any CSS property. The
example below shows how to change the text color and the left margin of a paragraph:
<p style="color:blue;margin-left:20px;">This is a paragraph.</p>
Example
<!DOCTYPE html>
<html>
<body style="background-color:yellow;">
<h2 style="background-color:red;">This is a heading</h2>
<p style="background-color:green;">This is a paragraph.</p>
</body>
</html>
[K 9 COMPUTER LABS]
Example
<!DOCTYPE html>
<html>
<body>
<h1 style="font-family:verdana;">A heading</h1>
<p style="font-family:arial;color:red;font-size:20px;">A paragraph.</p>
</body>
</html>
The font-family, color, and font-size properties make the old <font> tag obsolete.
Example
<!DOCTYPE html>
<html>
<body>
<h1 style="text-align:center;">Center-aligned heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
[K 9 COMPUTER LABS]
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>
Description
<style>
<link>
[K 9 COMPUTER LABS]
<!DOCTYPE html>
<html>
<body>
<h2>Spectacular Mountains</h2>
<img src="pic_mountain.jpg" alt="Mountain View" style="width:304px;height:228px">
</body>
</html>
Always specify the size of an image. If the size is unknown, the page will flicker while it loads.
Example
<img src="html5.gif" alt="The official HTML5 Icon">
The alt attribute is required. A web page will not validate correctly without it.
[K 9 COMPUTER LABS]
You can use the style attribute to specify the width and height of an image.
The values are specified in pixels (use px behind the value):
Example
<img src="html5.gif" alt="HTML5 Icon" style="width:128px;height:128px">
Example
<img src="html5.gif" alt="HTML5 Icon" width="128" height="128">
Example
<!DOCTYPE html>
<html>
<head>
<style>
img { width:100%; }
</style>
</head>
<body>
<img src="html5.gif" alt="HTML5 Icon" style="width:128px;height:128px">
<img src="html5.gif" alt="HTML5 Icon" width="128" height="128">
</body>
</html>
[K 9 COMPUTER LABS]
However, it is common on the web, to store images in a sub-folder, and refer to the folder in the image name:
Example
<img src="/images/html5.gif" alt="HTML5 Icon" style="width:128px;height:128px">
Example
<img src="wrongname.gif" alt="HTML5 Icon" style="width:128px;height:128px">
Example
<img src="http://www.k9computerlabs.com/images/k9_green.jpg">
Moving Images
The GIF standard allows moving images:
Example
<img src="programming.gif" alt="Computer Man" style="width:48px;height:48px">
Note that the syntax of inserting moving images is no different from non-moving images.
Example
<a href="default.asp">
<img src="smiley.gif" alt="HTML tutorial" style="width:42px;height:42px;border:0">
</a>
We have added border:0 to prevent IE9 (and earlier) from displaying a border around the image.
[K 9 COMPUTER LABS]
Image Maps
For an image, you can create an image map, with clickable areas:
Example
<img src="planets.gif" alt="Planets" usemap="#planetmap" style="width:145px;height:126px">
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" alt="Sun" href="sun.htm">
<area shape="circle" coords="90,58,3" alt="Mercury" href="mercur.htm">
<area shape="circle" coords="124,58,8" alt="Venus" href="venus.htm">
</map>
Image Floating
You can let an image float to the left or right of a paragraph:
Example
<p>
<img src="smiley.gif" alt="Smiley face" style="float:left;width:42px;height:42px">
A paragraph with an image. The image floats to the left of the text.
</p>
Use the width and height attributes to define the image size
[K 9 COMPUTER LABS]
First Name
Eve
John
Adam
Jill
<!DOCTYPE html>
<html>
<body>
<table style="width:100%">
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
Last Name
Jackson
Doe
Johnson
Smith
Points
94
80
67
50
[K 9 COMPUTER LABS]
</body>
</html>
[K 9 COMPUTER LABS]
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
</body>
</html>
The border attribute is on its way out of the HTML standard! It is better to use CSS.
To add borders, use the CSS border property:
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
[K 9 COMPUTER LABS]
<body>
<table style="width:100%">
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
</body>
</html>
Remember to define borders for both the table and the table cells.
[K 9 COMPUTER LABS]
<body>
<table style="width:100%">
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
[K 9 COMPUTER LABS]
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
</body>
</html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
[K 9 COMPUTER LABS]
th, td {
padding: 15px;
}
</style>
</head>
<body>
<table style="width:100%">
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
[K 9 COMPUTER LABS]
</table>
<p>Try to change the padding to 5px.</p>
</body>
</html>
[K 9 COMPUTER LABS]
<th>Points</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
</body>
</html>
To left-align the table headings, use the CSS text-align property:
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
[K 9 COMPUTER LABS]
border-collapse: collapse;
}
th, td {
padding: 5px;
}
th {
text-align: left;
}
</style>
</head>
<body>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Points</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
[K 9 COMPUTER LABS]
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
</body>
</html>
example
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
padding: 5px;
}
table {
border-spacing: 15px;
}
</style>
</head>
[K 9 COMPUTER LABS]
<body>
<table style="width:100%">
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
[K 9 COMPUTER LABS]
<td>Bill Gates</td>
<td>555 77 854</td>
<td>555 77 855</td>
</tr>
</table>
Example
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: left;
}
</style>
</head>
<body>
<h2>Cell that spans two columns:</h2>
<table style="width:100%">
<tr>
<th>Name</th>
<th colspan="2">Telephone</th>
</tr>
<tr>
[K 9 COMPUTER LABS]
<td>Bill Gates</td>
<td>555 77 854</td>
<td>555 77 855</td>
</tr>
</table>
</body>
</html>
Example
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
[K 9 COMPUTER LABS]
text-align: left;
}
</style>
</head>
<body>
<h2>Cell that spans two rows:</h2>
<table style="width:100%">
<tr>
<th>First Name:</th>
<td>Bill Gates</td>
</tr>
<tr>
<th rowspan="2">Telephone:</th>
<td>555 77 854</td>
</tr>
<tr>
<td>555 77 855</td>
</tr>
</table>
</body>
</html>
[K 9 COMPUTER LABS]
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$50</td>
</tr>
</table>
Example
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: left;
}
</style>
</head>
<body>
<table style="width:100%">
<caption>Monthly savings</caption>
<tr>
[K 9 COMPUTER LABS]
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$50</td>
</tr>
</table>
</body>
</html>
[K 9 COMPUTER LABS]
Now you can define a different styles for this table:
table.names {
width: 100%;
background-color: #f1f1c1;
}
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: left;
}
table.names {
width: 100%;
background-color: #f1f1c1;
}
</style>
</head>
<body>
<table style="width:100%">
<tr>
<th>First Name</th>
[K 9 COMPUTER LABS]
<th>Last Name</th>
<th>Points</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
<br>
<table class="names">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Points</th>
[K 9 COMPUTER LABS]
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
</body>
</html>
<!DOCTYPE html>
[K 9 COMPUTER LABS]
<html>
<head>
<style>
table {
width:100%;
}
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: left;
}
table.names tr:nth-child(even) {
background-color: #f1f1c1;
}
table.names tr:nth-child(odd) {
background-color:#ffffff;
}
table.names th
background-color: #c1c1c1;
}
</style>
[K 9 COMPUTER LABS]
</head>
<body>
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Points</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
[K 9 COMPUTER LABS]
</table>
<br>
<table class="names">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Points</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
</body>
[K 9 COMPUTER LABS]
</html>
Summary
Description
<table>
Defines a table
<th>
<tr>
<td>
<caption>
<colgroup>
<col>
<thead>
<tbody>
<tfoot>
#Practice
HTML <colgroup> Tag
Example
[K 9 COMPUTER LABS]
Set the background color of the three columns with the <colgroup> and <col> tags:
<table>
<colgroup>
<col span="2" style="background-color:red">
<col style="background-color:yellow">
</colgroup>
<tr>
<th>ISBN</th>
<th>Title</th>
<th>Price</th>
</tr>
<tr>
<td>3476896</td>
<td>My first HTML</td>
<td>$53</td>
</tr>
</table>
The <colgroup> tag specifies a group of one or more columns in a table for formatting.
The <colgroup> tag is useful for applying styles to entire columns, instead of repeating the styles for each cell, for each
row.
Note: The <colgroup> tag must be a child of a <table> element, after any <caption> elements and before any <thead>,
<tbody>, <tfoot>, and <tr> elements.
Tip: To define different properties to a column within a <colgroup>, use the <col> tag within the <colgroup> tag.
<!DOCTYPE html>
<html>
<head>
<style>
table,th,td
{
border:1px solid black;
}
</style>
</head>
[K 9 COMPUTER LABS]
<body>
<table>
<colgroup>
<col span="2" style="background-color:red">
<col style="background-color:yellow">
</colgroup>
<tr>
<th>ISBN</th>
<th>Title</th>
<th>Price</th>
</tr>
<tr>
<td>3476896</td>
<td>My first HTML</td>
<td>$53</td>
</tr>
<tr>
<td>5869207</td>
<td>My first CSS</td>
<td>$49</td>
</tr>
</table>
[K 9 COMPUTER LABS]
</body>
</html>
#Practice
HTML <thead> Tag
Example
An HTML table with a <thead>, <tfoot>, and a <tbody> element:
<table>
<thead>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
</thead>
<tfoot>
<tr>
<td>Sum</td>
<td>$180</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</tbody>
</table>
[K 9 COMPUTER LABS]
The <thead> tag must be used in the following context: As a child of a <table> element, after any <caption>, and
<colgroup> elements, and before any <tbody>, <tfoot>, and <tr> elements.
<!DOCTYPE html>
<html>
<head>
<style>
thead {color:green;}
tbody {color:blue;}
tfoot {color:red;}
table,th,td
{
border:1px solid black;
}
</style>
</head>
<body>
<table>
<thead>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
</thead>
<tfoot>
<tr>
[K 9 COMPUTER LABS]
<td>Sum</td>
<td>$180</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</tbody>
</table>
<p><b>Tip:</b> The thead, tbody, and tfoot elements will not affect the layout of the table by default. However, you can use CSS to
style these elements.</p>
</body>
</html>
HTML Lists
1.
2.
[K 9 COMPUTER LABS]
3.
4.
Unordered List:
Syntax:
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
example
<!DOCTYPE html>
<html>
<body>
<h2>Unordered List with Default Bullets</h2>
<ul>
<li>Apples</li>
<li>Bananas</li>
<li>Lemons</li>
<li>Oranges</li>
</ul>
</body>
</html>
Description
The list items will be marked with bullets (default)
The list items will be marked with circles
The list items will be marked with squares
[K 9 COMPUTER LABS]
list-style-type:none
Disc:
<ul style="list-style-type:disc">
<li>Coffee</li>
<li>Tea
<li>Milk</li>
</ul>
<!DOCTYPE html>
<html>
<body>
<h2>Unordered List with Disc Bullets</h2>
<ul style="list-style-type:disc">
<li>Apples</li>
<li>Bananas</li>
<li>Lemons</li>
<li>Oranges</li>
</ul>
</body>
</html>
Circle:
syntax
<ul style="list-style-type:circle">
<li>Coffee</li>
<li>Tea
<li>Milk</li>
</ul>
example
<!DOCTYPE html>
<html>
<body>
<h2>Unordered List with Circle Bullets</h2>
<ul style="list-style-type:circle">
<li>Apples</li>
[K 9 COMPUTER LABS]
<li>Bananas</li>
<li>Lemons</li>
<li>Oranges</li>
</ul>
</body>
</html>
Square:
<ul style="list-style-type:square">
<li>Coffee</li>
<li>Tea
<li>Milk</li>
</ul>
None:
<ul style="list-style-type:none">
<li>Coffee</li>
<li>Tea
<li>Milk</li>
</ul>
Ordered List:
<ol>
<li>Coffee</li>
<li>Milk</li>
</ol>
<!DOCTYPE html>
<html>
<body>
<h2>Ordered List</h2>
<ol>
<li>Apples</li>
<li>Bananas</li>
<li>Lemons</li>
<li>Oranges</li>
[K 9 COMPUTER LABS]
</ol>
</body>
</html>
Description
The list items will be numbered with numbers (default)
The list items will be numbered with uppercase letters
The list items will be numbered with lowercase letters
The list items will be numbered with uppercase roman numbers
The list items will be numbered with lowercase roman numbers
<!DOCTYPE html>
<html>
<body>
<h2>Ordered List with Letters</h2>
<ol type="A">
<li>Apples</li>
<li>Bananas</li>
<li>Lemons</li>
<li>Oranges</li>
</ol>
</body>
</html>
Description List:
<dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold drink</dd>
</dl>
[K 9 COMPUTER LABS]
Example
<!DOCTYPE html>
<html>
<body>
<h2>A Description List</h2>
<dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold drink</dd>
</dl>
</body>
</html>
Nested Lists:
<ul>
<li>Coffee</li>
<li>Tea
<ul>
<li>Black tea</li>
<li>Green tea</li>
</ul>
</li>
<li>Milk</li>
</ul>
List items can contain new list, and other HTML elements, like images and links, etc.
<!DOCTYPE html>
<html>
<body>
<h2>A Nested List</h2>
<ul>
<li>Coffee</li>
<li>Tea
[K 9 COMPUTER LABS]
<ul>
<li>Black tea</li>
<li>Green tea</li>
</ul>
</li>
<li>Milk</li>
</ul>
</body>
</html>
Horizontal Lists
HTML lists can be styled in many different ways with CSS.
One popular way, is to style a list to display horizontally:
Horizontal List:
<!DOCTYPE html>
<html>
<head>
<style>
ul.menu li {
display:inline;
}
</style>
</head>
<body>
<h2>Horizontal List</h2>
<ul class="menu">
<li>Apples</li>
<li>Bananas</li>
<li>Lemons</li>
<li>Oranges</li>
</ul>
</body>
</html>
With a little extra style, you can make it look like a menu:
New Style:syntax
ul.menu {
padding: 0;
}
ul.menu li {
[K 9 COMPUTER LABS]
display: inline;
}
ul.menu li a {
background-color: black;
color: white;
padding: 10px 20px;
text-decoration: none;
border-radius: 4px 4px 0 0;
}
ul.menu li a:hover {
background-color: orange;
}
Example
<!DOCTYPE html>
<html>
<head>
<style>
ul.menu {
padding: 0;
}
ul.menu li {
display: inline;
}
ul.menu li a {
background-color: black;
color: white;
padding: 10px 20px;
text-decoration: none;
border-radius: 4px 4px 0 0;
}
ul.menu li a:hover {
background-color: orange;
}
[K 9 COMPUTER LABS]
</style>
</head>
<body>
<h2>Horizontal List</h2>
<ul class="menu">
<li><a href="html_tables.asp">Tables</a></li>
<li><a href="html_lists.asp">Lists</a></li>
<li><a href="html_blocks.asp">Blocks</a></li>
<li><a href="html_classes.asp">Classes</a></li>
</ul>
</body>
</html>
Chapter Summary
Description
Defines an unordered list
[K 9 COMPUTER LABS]
<ol>
<li>
<dl>
<dt>
<dd>
[K 9 COMPUTER LABS]
Example
<!DOCTYPE html>
<html>
<body>
<div style="background-color:black; color:white; margin:20px; padding:20px;">
<h2>London</h2>
<p>
London is the capital city of England. It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million
inhabitants.
</p>
<p>
Standing on the River Thames, London has been a major settlement for two millennia, its history going back to its founding by the
Romans, who named it Londinium.
</p>
</div>
</body>
</html>
[K 9 COMPUTER LABS]
The <div> element has no special meaning. It has no required attributes, but style and class are common.
Because it is a block level element, the browser will display line breaks before and after it.
When used together with CSS, the <div> element can be used to style blocks of content.
Example
<h1>My <span style="color:red">Important</span>Heading</h1>
<!DOCTYPE html>
<html>
<body>
Description
<div>
<span>
HTML Classes
Classing HTML elements, makes it possible to define CSS styles for classes of elements.
Equal styles for equal classes, or different styles for different classes.
<!DOCTYPE html>
<html>
<head>
<style>
.cities {
[K 9 COMPUTER LABS]
background-color:black;
color:white;
margin:20px;
padding:20px;
}
</style>
</head>
<body>
<div class="cities">
<h2>London</h2>
<p>London is the capital city of England. It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million
inhabitants.</p>
<p>Standing on the River Thames, London has been a major settlement for two millennia, its history going back to its founding by the Romans, who
named it Londinium.</p>
</div>
</body>
</html>
[K 9 COMPUTER LABS]
padding:20px;
}
</style>
</head>
<body>
<div class="cities">
<h2>London</h2>
<p>London is the capital city of England. It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million
inhabitants.</p>
<p>Standing on the River Thames, London has been a major settlement for two millennia, its history going back to its founding by the Romans, who
named it Londinium.</p>
</div>
<div class="cities">
<h2>Paris</h2>
<p>Paris is the capital and most populous city of France.</p>
<p>Situated on the Seine River, it is at the heart of the le-de-France region, also known as the rgion parisienne.</p>
<p>Within its metropolitan area is one of the largest population centers in Europe, with over 12 million inhabitants.</p>
</div>
<div class="cities">
<h2>Tokyo</h2>
<p>Tokyo is the capital of Japan, the center of the Greater Tokyo Area, and the most populous metropolitan area in the world.</p>
<p>It is the seat of the Japanese government and the Imperial Palace, and the home of the Japanese Imperial Family.</p>
<p>The Tokyo prefecture is part of the world's most populous metropolitan area with 38 million people and the world's largest urban economy.</p>
</div>
</body>
</html>
[K 9 COMPUTER LABS]
Classing <span> elements makes it possible to design equal styles for equal <span> elements
<!DOCTYPE html>
<html>
<head>
<style>
span.red {
color:red;
}
</style>
</head>
<body>
<h1>My <span class="red">Important</span> Heading</h1>
</body>
</html>
[K 9 COMPUTER LABS]
HTML Layouts
Websites often display content in multiple columns (like a magazine or newspaper).
[K 9 COMPUTER LABS]
its history going back to its founding by the Romans, who named it Londinium.
</p>
</div>
<div id="footer">
Copyright K9computerlabs.com
</div>
</body>
The CSS
style>
#header {
background-color:black;
color:white;
text-align:center;
padding:5px;
}
#nav {
line-height:30px;
background-color:#eeeeee;
height:300px;
width:100px;
float:left;
padding:5px;
}
#section {
width:350px;
float:left;
padding:10px;
}
#footer {
background-color:black;
color:white;
clear:both;
text-align:center;
padding:5px;
}
</style>
<!DOCTYPE html>
<html>
<head>
<style>
#header {
[K 9 COMPUTER LABS]
background-color:black;
color:white;
text-align:center;
padding:5px;
}
#nav {
line-height:30px;
background-color:#eeeeee;
height:300px;
width:100px;
float:left;
padding:5px;
}
#section {
width:350px;
float:left;
padding:10px;
}
#footer {
background-color:black;
color:white;
clear:both;
text-align:center;
padding:5px;
}
</style>
[K 9 COMPUTER LABS]
</head>
<body>
<div id="header">
<h1>City Gallery</h1>
</div>
<div id="nav">
London<br>
Paris<br>
Tokyo<br>
</div>
<div id="section">
<h2>London</h2>
<p>
London is the capital city of England. It is the most populous city in the United Kingdom,
with a metropolitan area of over 13 million inhabitants.
</p>
<p>
Standing on the River Thames, London has been a major settlement for two millennia,
its history going back to its founding by the Romans, who named it Londinium.
</p>
</div>
<div id="footer">
Copyright K9ComputerLabs.com
</div>
</body>
</html>
[K 9 COMPUTER LABS]
header
nav
section
article
aside
footer
details
summary
This example uses <header>, <nav>, <section>, and <footer> to create a multiple column layout:
<!DOCTYPE html>
<html>
<head>
<style>
header {
background-color:black;
color:white;
text-align:center;
padding:5px;
}
nav {
line-height:30px;
background-color:#eeeeee;
height:300px;
width:100px;
[K 9 COMPUTER LABS]
float:left;
padding:5px;
}
section {
width:350px;
float:left;
padding:10px;
}
footer {
background-color:black;
color:white;
clear:both;
text-align:center;
padding:5px;
}
</style>
</head>
<body>
<header>
<h1>City Gallery</h1>
</header>
<nav>
London<br>
Paris<br>
Tokyo<br>
</nav>
[K 9 COMPUTER LABS]
<section>
<h1>London</h1>
<p>
London is the capital city of England. It is the most populous city in the United Kingdom,
with a metropolitan area of over 13 million inhabitants.
</p>
<p>
Standing on the River Thames, London has been a major settlement for two millennia,
its history going back to its founding by the Romans, who named it Londinium.
</p>
</section>
<footer>
Copyright K9ComputerLabs.com
</footer>
</body>
</html>
HTML Forms
HTML forms are used to pass data to a server.
[K 9 COMPUTER LABS]
An HTML form can contain input elements like text fields, checkboxes, radio-buttons, submit buttons and more. A form
can also contain select lists, textarea, fieldset, legend, and label elements.
The <form> tag is used to create an HTML form:
<form>
.
input elements
.
</form>
Text Fields
<input type="text"> defines a one-line input field that a user can enter text into:
<form>
First name: <input type="text" name="firstname"><br>
Last name: <input type="text" name="lastname">
</form>
How the HTML code above looks in a browser:
First name:
Last name:
Note: The form itself is not visible. Also note that the default width of a text field is 20 characters.
Password Field
<input type="password"> defines a password field:
[K 9 COMPUTER LABS]
<form>
Password: <input type="password" name="pwd">
</form>
How the HTML code above looks in a browser:
Password:
Note: The characters in a password field are masked (shown as asterisks or circles).
Radio Buttons
<input type="radio"> defines a radio button. Radio buttons let a user select ONLY ONE of a limited number of choices:
<form>
<input type="radio" name="sex" value="male">Male<br>
<input type="radio" name="sex" value="female">Female
</form>
How the HTML code above looks in a browser:
Male
Female
Checkboxes
<input type="checkbox"> defines a checkbox. Checkboxes let a user select ZERO or MORE options of a limited number
of choices.
<form>
<input type="checkbox" name="vehicle" value="Bike">I have a bike<br>
<input type="checkbox" name="vehicle" value="Car">I have a car
</form>
How the HTML code above looks in a browser:
I have a bike
I have a car
Submit Button
[K 9 COMPUTER LABS]
<input type="submit"> defines a submit button.
A submit button is used to send form data to a server. The data is sent to the page specified in the form's action attribute.
The file defined in the action attribute usually does something with the received input:
<form name="input" action="demo_form_action.asp" method="get">
Username: <input type="text" name="user">
<input type="submit" value="Submit">
</form>
How the HTML code above looks in a browser:
Username:
If you type some characters in the text field above, and click the "Submit" button, the browser will send your input to a
page called "demo_form_action.asp". The page will show you the received input.
Description
<form>
<input>
<textarea>
<label>
<fieldset>
<legend>
<select>
<optgroup>
<option>
<button>
<datalist>
<keygen>
<output>
[K 9 COMPUTER LABS]
HTML <fieldset> Tag
Example
Group related elements in a form:
<form>
<fieldset>
<legend>Personalia:</legend>
Name: <input type="text"><br>
Email: <input type="text"><br>
Date of birth: <input type="text">
</fieldset>
</form>
Example
Create a drop-down list with four options:
<!DOCTYPE html>
<html>
<body>
<select>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
</body>
</html>
[K 9 COMPUTER LABS]
The <select> element is used to create a drop-down list.
The <option> tags inside the <select> element define the available options in the list.
Example
Group related options with <optgroup> tags:
<select>
<optgroup label="Swedish Cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
</optgroup>
<optgroup label="German Cars">
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</optgroup>
</select>
<select>
<optgroup label="Swedish Cars">
[K 9 COMPUTER LABS]
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
</optgroup>
<optgroup label="German Cars">
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</optgroup>
</select>
</body>
</html>
Example
An <input> element with pre-defined values in a <datalist>:
<input list="browsers">
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
[K 9 COMPUTER LABS]
<html>
<body>
<p><strong>Note:</strong> The datalist tag is not supported in Internet Explorer 9 and earlier versions, or in Safari.</p>
</body>
</html>
Example
A clickable button is marked up as follows:
<button type="button">Click Me!</button>
[K 9 COMPUTER LABS]
Inside a <button> element you can put content, like text or images. This is the difference between this element and buttons
created with the <input> element.
Tip: Always specify the type attribute for a <button> element. Different browsers use different default types for the
<button> element.
<!DOCTYPE html>
<html>
<body>
<button type="button" onclick="alert('Hello world!')">Click Me!</button>
</body>
</html>
Example
A form with a keygen field:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
[K 9 COMPUTER LABS]
The <keygen> tag specifies a key-pair generator field used for forms.
When the form is submitted, the private key is stored locally, and the public key is sent to the server.
HTML Iframes
An iframe is used to display a web page within a web page.
<!DOCTYPE html>
<html>
<body>
<iframe src="demo_iframe.htm" frameborder="0"></iframe>
</body>
</html>
he src attribute specifies the URL (web address) of the iframe page.
Example
<iframe src="demo_iframe.htm" width="200" height="200"></iframe>
<!DOCTYPE html>
<html>
<body>
[K 9 COMPUTER LABS]
<iframe src="demo_iframe.htm" width="200" height="200"></iframe>
</body>
</html>
Example
<iframe src="demo_iframe.htm" frameborder="0"></iframe>
Example
<iframe src="demo_iframe.htm" name="iframe_a"></iframe>
<p><a href="http://www.k9computerlabs.com" target="iframe_a">k9computerlabs</a></p>
[K 9 COMPUTER LABS]
Color Name
HEX
AliceBlue
#F0F8FF
AntiqueWhite
#FAEBD7
Aqua
#00FFFF
Aquamarine
#7FFFD4
Azure
#F0FFFF
Beige
#F5F5DC
Bisque
#FFE4C4
Black
#000000
BlanchedAlmond
#FFEBCD
Blue
#0000FF
BlueViolet
#8A2BE2
Brown
#A52A2A
BurlyWood
#DEB887
CadetBlue
#5F9EA0
Chartreuse
#7FFF00
Chocolate
#D2691E
Coral
#FF7F50
CornflowerBlue
#6495ED
Cornsilk
#FFF8DC
Crimson
#DC143C
Cyan
#00FFFF
DarkBlue
#00008B
DarkCyan
#008B8B
DarkGoldenRod
#B8860B
DarkGray
#A9A9A9
DarkGreen
#006400
DarkKhaki
#BDB76B
DarkMagenta
#8B008B
DarkOliveGreen
#556B2F
DarkOrange
#FF8C00
Color
[K 9 COMPUTER LABS]
DarkOrchid
#9932CC
DarkRed
#8B0000
DarkSalmon
#E9967A
DarkSeaGreen
#8FBC8F
DarkSlateBlue
#483D8B
DarkSlateGray
#2F4F4F
DarkTurquoise
#00CED1
DarkViolet
#9400D3
DeepPink
#FF1493
DeepSkyBlue
#00BFFF
DimGray
#696969
DodgerBlue
#1E90FF
FireBrick
#B22222
FloralWhite
#FFFAF
ForestGreen
#228B22
Fuchsia
#FF00FF
Gainsboro
#DCDCDC
GhostWhite
#F8F8FF
Gold
#FFD700
GoldenRod
#DAA520
Gray
#808080
Green
#008000
GreenYellow
#ADFF2F
HoneyDew
#F0FFF0
HotPink
#FF69B4
IndianRed
#CD5C5C
Indigo
#4B0082
Ivory
#FFFFF0
Khaki
#F0E68C
Lavender
#E6E6FA
LavenderBlush
#FFF0F5
[K 9 COMPUTER LABS]
LawnGreen
#7CFC00
LemonChiffon
#FFFACD
LightBlue
#ADD8E6
LightCoral
#F08080
LightCyan
#E0FFFF
LightGoldenRodYel
#FAFAD2
low
LightGray
#D3D3D3
LightGreen
#90EE90
LightPink
#FFB6C1
LightSalmon
#FFA07A
LightSeaGreen
#20B2AA
LightSkyBlue
#87CEFA
LightSlateGray
#778899
LightSteelBlue
#B0C4DE
LightYellow
#FFFFE0
Lime
#00FF00
LimeGreen
#32CD32
Linen
#FAF0E6
Magenta
#FF00FF
Maroon
#800000
MediumAquaMarin
#66CDAA
e
MediumBlue
#0000CD
MediumOrchid
#BA55D3
MediumPurple
#9370DB
MediumSeaGreen #3CB371
MediumSlateBlue #7B68EE
MediumSpringGre
#00FA9A
en
MediumTurquoise #48D1CC
MediumVioletRed #C71585
[K 9 COMPUTER LABS]
MidnightBlue
#191970
MintCream
#F5FFFA
MistyRose
#FFE4E1
Moccasin
#FFE4B5
NavajoWhite
#FFDEAD
Navy
#000080
OldLace
#FDF5E6
Olive
#808000
OliveDrab
#6B8E23
Orange
#FFA500
OrangeRed
#FF4500
Orchid
#DA70D6
PaleGoldenRod
#EEE8AA
PaleGreen
#98FB98
PaleTurquoise
#AFEEEE
PaleVioletRed
#DB7093
PapayaWhip
#FFEFD5
PeachPuff
#FFDAB9
Peru
#CD853F
Pink
#FFC0CB
Plum
#DDA0DD
PowderBlue
#B0E0E6
Purple
#800080
Red
#FF0000
RosyBrown
#BC8F8F
RoyalBlue
#4169E1
SaddleBrown
#8B4513
Salmon
#FA8072
SandyBrown
#F4A460
SeaGreen
#2E8B57
SeaShell
#FFF5EE
[K 9 COMPUTER LABS]
Sienna
#A0522D
Silver
#C0C0C0
SkyBlue
#87CEEB
SlateBlue
#6A5ACD
SlateGray
#708090
Snow
#FFFAFA
SpringGreen
#00FF7F
SteelBlue
#4682B4
Tan
#D2B48C
Teal
#008080
Thistle
#D8BFD8
Tomato
#FF6347
Turquoise
#40E0D0
Violet
#EE82EE
Wheat
#F5DEB3
White
#FFFFFF
WhiteSmoke
#F5F5F5
Yellow
#FFFF00
YellowGreen
#9ACD32
Color Values
Colors are defined using a hexadecimal (hex) notation for the combination of Red, Green, and Blue values (RGB).
The lowest value for each of the light sources is 0 (hex 00). The highest value is 255 (hex FF).
Hex values are written as # followed by either three or six hexadecimal characters.
Three three-digit notations (#rgb) are converted to six digits (#rrggbb).
[K 9 COMPUTER LABS]
HTML Color Shades
000033
003333
006633
009933
00CC33
00FF33
330033
333333
336633
339933
33CC33
33FF33
660033
663333
666633
669933
66CC33
66FF33
990033
993333
996633
999933
99CC33
99FF33
CC0033
CC3333
CC6633
CC9933
CCCC33
CCFF33
FF0033
FF3333
FF6633
000066
003366
006666
009966
00CC66
00FF66
330066
333366
336666
339966
33CC66
33FF66
660066
663366
666666
669966
66CC66
66FF66
990066
993366
996666
999966
99CC66
99FF66
CC0066
CC3366
CC6666
CC9966
CCCC66
CCFF66
FF0066
FF3366
FF6666
000099
003399
006699
009999
00CC99
00FF99
330099
333399
336699
339999
33CC99
33FF99
660099
663399
666699
669999
66CC99
66FF99
990099
993399
996699
999999
99CC99
99FF99
CC0099
CC3399
CC6699
CC9999
CCCC99
CCFF99
FF0099
FF3399
FF6699
0000CC
0033CC
0066CC
0099CC
00CCCC
00FFCC
3300CC
3333CC
3366CC
3399CC
33CCCC
33FFCC
6600CC
6633CC
6666CC
6699CC
66CCCC
66FFCC
9900CC
9933CC
9966CC
9999CC
99CCCC
99FFCC
CC00CC
CC33CC
CC66CC
CC99CC
CCCCCC
CCFFCC
FF00CC
FF33CC
FF66CC
0000FF
0033FF
0066FF
0099FF
00CCFF
00FFFF
3300FF
3333FF
3366FF
3399FF
33CCFF
33FFFF
6600FF
6633FF
6666FF
6699FF
66CCFF
66FFFF
9900FF
9933FF
9966FF
9999FF
99CCFF
99FFFF
CC00FF
CC33FF
CC66FF
CC99FF
CCCCFF
CCFFFF
FF00FF
FF33FF
FF66FF
[K 9 COMPUTER LABS]
FF9900
FFCC00
FFFF00
FF9933
FFCC33
FFFF33
FF9966
FFCC66
FFFF66
FF9999
FFCC99
FFFF99
FF99CC
FFCCCC
FFFFCC
FF99FF
FFCCFF
FFFFFF
HTML Scripts
JavaScripts make HTML pages more dynamic and interactive.
[K 9 COMPUTER LABS]
<script>
document.getElementById("demo").innerHTML = "Hello JavaScript!";
</script>
<noscript>Sorry, your browser does not support JavaScript!</noscript>
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = "Hello JavaScript!";
</script>
<noscript>Sorry, your browser does not support JavaScript!</noscript>
<p>A browser without support for JavaScript will show the text written inside the noscript element.</p>
</body>
</html>
A Taste of JavaScript
Here are some examples of what JavaScript can do:
[K 9 COMPUTER LABS]
document.getElementById("demo").innerHTML = "Hello JavaScript!";
}
</script>
</body>
</html>
[K 9 COMPUTER LABS]
function light(sw) {
var pic;
if (sw == 0) {
pic = "pic_bulboff.gif"
} else {
pic = "pic_bulbon.gif"
}
document.getElementById('myImage').src = pic;
}
</script>
<img id="myImage" src="pic_bulboff.gif" width="100" height="180">
<p>
<button type="button" onclick="light(1)">Light On</button>
<button type="button" onclick="light(0)">Light Off</button>
</p>
</body>
</html>
Description
<script>
<noscript>
Defines an alternate content for users that do not support client-side scripts
HTML Head
[K 9 COMPUTER LABS]
Example
<head>
<base href="http://www.k9computerlabs.com/images/" target="_blank">
</head>
Example
[K 9 COMPUTER LABS]
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
Example
<head>
<style">
body {background-color:yellow;}
p {color:blue;}
</style>
</head>
Example
<meta name="keywords" content="HTML, CSS, XML, XHTML, JavaScript">
Example
<meta name="description" content="Welcome to the world of HTML and CSS">
[K 9 COMPUTER LABS]
Example
<meta name="author" content="Hege Refsnes">
Example
<meta http-equiv="refresh" content="30">
Example
<script>
document.getElementById("demo").innerHTML = "Hello JavaScript!";
</script>
Description
<head>
<title>
<base>
<link>
<meta>
<script>
<style>
HTML Entities
Reserved characters in HTML must be replaced with character entities.
Characters, not present on your keyboard, can also be replaced by entities.
[K 9 COMPUTER LABS]
HTML Entities
OR
&#entity_number;
A common character entity used in HTML is the non breaking space ( ).
Remember that browsers will always truncate spaces in HTML pages. If you write 10 spaces in your text, the
browser will remove 9 of them. To add real spaces to your text, you can use the character entity.
Some Other Useful HTML Character Entities
Result
Description
Entity Name
Entity Number
non-breaking space
 
<
less than
<
<
>
greater than
>
>
&
ampersand
&
&
cent
¢
¢
pound
£
£
yen
¥
¥
euro
€
€
[K 9 COMPUTER LABS]
copyright
©
©
registered trademark
®
®
Example
<p>I will display €</p>
<p>I will display €</p>
<p>I will display €</p>
Number
Entity
Description
∀ ∀
FOR ALL
∂ ∂
PARTIAL DIFFERENTIAL
∃ ∃
THERE EXISTS
∅ ∅
EMPTY SETS
∇ ∇
NABLA
[K 9 COMPUTER LABS]
∈ ∈
ELEMENT OF
∉ ∉
NOT AN ELEMENT OF
∋ ∋
CONTAINS AS MEMBER
∏ ∏
N-ARY PRODUCT
∑ ∑
N-ARY SUMMATION
Number
Entity
Description
Α
Α
Β
Β
Γ
Γ
Δ
Δ
Ε
Ε
Ζ
Ζ
Number
Entity
Description
©
©
COPYRIGHT SIGN
®
®
REGISTERED SIGN
€ €
EURO SIGN
™ ™
TRADEMARK
← ←
LEFTWARDS ARROW
↑ ↑
UPWARDS ARROW
→ →
RIGHTWARDS ARROW
↓ ↓
DOWNWARDS ARROW
♠ ♠
♣ ♣
[K 9 COMPUTER LABS]
♥ ♥
♦ ♦
Why XHTML?
XML is a markup language where documents must be marked up correctly and must be "well-formed".
Today's market consists of different browser technologies. Some browsers run on computers, and some
browsers run on mobile phones or other small devices. Smaller devices often lack the resources or power to
interpret a "bad" markup language.
Therefore - by combining the strengths of HTML and XML, XHTML was developed. XHTML is HTML
redesigned as XML.
[K 9 COMPUTER LABS]
XHTML Elements
XHTML Attributes
[K 9 COMPUTER LABS]
<body>
......
</body>
</html>
XHTML Elements Must Be Properly Nested
In HTML, some elements can be improperly nested within each other, like this:
<b><i>This text is bold and italic</b></i>
In XHTML, all elements must be properly nested within each other, like this:
<b><i>This text is bold and italic</i></b>
XHTML Elements Must Always Be Closed
This is wrong:
<p>This is a paragraph
<p>This is another paragraph
This is correct:
<p>This is a paragraph</p>
<p>This is another paragraph</p>
This is wrong:
A break: <br>
A horizontal rule: <hr>
An image: <img src="happy.gif" alt="Happy face">
This is correct:
A break: <br />
A horizontal rule: <hr />
An image: <img src="happy.gif" alt="Happy face" />
XHTML Elements Must Be In Lower Case
This is wrong:
[K 9 COMPUTER LABS]
<BODY>
<P>This is a paragraph</P>
</BODY>
This is correct:
<body>
<p>This is a paragraph</p>
</body>
XHTML Attribute Names Must Be In Lower Case
This is wrong:
<table WIDTH="100%">
This is correct:
<table width="100%">
Attribute Values Must Be Quoted
This is wrong:
<table width=100%>
This is correct:
<table width="100%">
Attribute Minimization Is Forbidden
This is wrong:
<input checked>
<input readonly>
<input disabled>
<option selected>
This is correct:
<input checked="checked">
<input readonly="readonly">
<input disabled="disabled">
<option selected="selected">
[K 9 COMPUTER LABS]
How to Convert from HTML to XHTML
1. Add an XHTML <!DOCTYPE> to the first line of every page
2. Add an xmlns attribute to the html element of every page
3. Change all element names to lowercase
4. Close all empty elements
5. Change all attribute names to lowercase
6. Quote all attribute values
HTML5 Introduction
HTML5 is the latest HTML standard. It walks hand in hand with CSS3, the latest CSS standard.
HTML5
CSS3
HTML5
HTML5
HTML5
HTML5
HTML5
HTML5
HTML5
HTML5
HTML5
CSS3 Borders
CSS3 Backgrounds
CSS3 Gradients
CSS3 Fonts
CSS3 2D
Transforms
CSS3 3D
Transforms
CSS3 Transitions
CSS3 Animations
CSS3 Columns
CSS3 User
Interface
Elements
Semantic
Input types
Graphics
Video / Audio
Geolocation
Drag / Drop
Local Storage
Web Workers
[K 9 COMPUTER LABS]
<meta charset="UTF-8">
HTML5 Example:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
</head>
<body>
Content of the document......
</body>
</html>
The default character encoding in HTML5 is UTF-8.
HTML Geolocation
[K 9 COMPUTER LABS]
HTML SSE
Local storage is a powerful replacement for cookies.
<acronym>
<applet>
<basefont>
<big>
<center>
<dir>
<font>
<frame>
<frameset>
<noframes>
<strike>
<tt>
A semantic element clearly describes its meaning to both the browser and the developer.
Examples of non-semantic elements: <div> and <span> - Tells nothing about its content.
[K 9 COMPUTER LABS]
Examples of semantic elements: <form>, <table>, and <img> - Clearly defines its content.
Browser Support
Many web sites contain HTML code like: <div id="nav"> <div class="header"> <div id="footer">
to indicate navigation, header, and footer.
HTML5 offers new semantic elements to define different parts of a web page:
<article>
<aside>
<details>
<figcaption>
<figure>
<footer>
<header>
<main>
<mark>
<nav>
<section>
<summary>
<time>
[K 9 COMPUTER LABS]
<section>
<h1>WWF</h1>
<p>
The World Wide Fund for Nature (WWF) is an international organization working on issues
regarding the conservation, research and restoration of the environment, formerly named the
World Wildlife Fund. WWF was founded in 1961.
</p>
</section>
[K 9 COMPUTER LABS]
<section>
<h1>WWF's Panda symbol</h1>
<p>
The Panda has become the symbol of WWF. The well-known panda logo of WWF originated from a
panda named Chi Chi that was transferred from the Beijing Zoo to the London Zoo in the same
year of the establishment of WWF.
</p>
</section>
</body>
</html>
HTML5 <article> Element
Forum post
Blog post
Newspaper article
Example
<!DOCTYPE html>
<html>
<body>
<article>
<h1>Internet Explorer 9</h1>
<p>
Windows Internet Explorer 9 (abbreviated as IE9) was released to
[K 9 COMPUTER LABS]
the public on March 14, 2011 at 21:00 PDT.
</p>
</article>
</body>
</html>
In the HTML5 standard, the <article> element defines a complete, self-contained block of related elements.
The <section> element is defined as a block of related elements.
Can we use the definitions to decide how to nest elements? No, we cannot!
On the Internet, you will find HTML pages with <section> elements containing <article> elements, and
<article> elements containing <sections> elements.
You will also find pages with <section> elements containing <section> elements, and <article> elements
containing <article> elements.
Newspaper: The sports articles in the sports section, have a technical section in each
article.
[K 9 COMPUTER LABS]
<article>
<header>
<h1>Internet Explorer 9</h1>
<p><time pubdate datetime="2011-03-15"></time></p>
</header>
<p>Windows Internet Explorer 9 (abbreviated as IE9) was released to
the public on March 14, 2011 at 21:00 PDT.</p>
</article>
</body>
</html>
HTML5 <footer> Element
<footer>
<p>Posted by: Hege Refsnes</p>
<p><time pubdate datetime="2012-03-01"></time></p>
</footer>
[K 9 COMPUTER LABS]
</body>
</html>
HTML5 <nav> Element
<nav>
<a href="/html/">HTML</a> |
<a href="/css/">CSS</a> |
<a href="/js/">JavaScript</a> |
<a href="/jquery/">jQuery</a>
</nav>
</body>
</html>
HTML5 <aside> Element
The <aside> element defines some content aside from the content it is placed in (like a sidebar).
The aside content should be related to the surrounding content.
Example
<!DOCTYPE html>
<html>
[K 9 COMPUTER LABS]
<body>
<aside>
<h4>Epcot Center</h4>
<p>The Epcot Center is a theme park in Disney World, Florida.</p>
</aside>
</body>
</html>
HTML5 <figure> and <figcaption> Elements
<!DOCTYPE html>
<html>
<body>
<p>The Pulpit Rock is a massive cliff 604 metres (1982 feet) above
Lysefjorden, opposite the Kjerag plateau, in Forsand, Ryfylke, Norway. The
top of the cliff is approximately 25 by 25 metres (82 by 82 feet) square and
almost flat, and is a famous tourist attraction in Norway.</p>
<figure>
[K 9 COMPUTER LABS]
</body>
</html>
Why Semantic HTML5 Elements?
With HTML4, developers used their own favorite attribute names to style page elements:
header, top, bottom, footer, menu, navigation, main, container, content, article, sidebar, topnav, ...
This made it impossible for search engines to identify the correct web page content.
With HTML5 elements like: <header> <footer> <nav> <section> <article>, this will become easier.
According to the W3C, a Semantic Web:
"Allows data to be shared and reused across applications, enterprises, and communities."
Description
<article>
Defines an article
<aside>
<details>
<figcaption>
<figure>
<footer>
<header>
[K 9 COMPUTER LABS]
<main>
<mark>
<nav>
<section>
<summary>
<time>
Defines a date/time