Professional Documents
Culture Documents
HTML Example
A small HTML document:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
Example Explained
The
The
The
The
The
The
The
Using this description, a web browser can display a document with a heading and a
paragraph.
HTML Tags
HTML tags are keywords (tag names) surrounded by angle brackets:
<tagname>content</tagname>
The start tag is often called the opening tag. The end tag is often called
the closing tag.
Web Browsers
The purpose of a web browser (Chrome, IE, Firefox, Safari) is to read HTML documents and
display them.
The browser does not display the tags, but uses them to determine how to display the
document:
Only the <body> area (the white area) is displayed by the browser.
You can use either .htm or .html as file extension. There is no difference, it
is up to you.
Example
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
Example
<html>
<body>
<p>This is a paragraph
<p>This is a paragraph
</body>
</html>
HTML Elements
HTML elements are written with a start tag, with an end tag, with the content in between:
<tagname>content</tagname>
The HTML element is everything from the start tag to the end tag:
Example
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
10
HTML Headings
HTML headings are defined with the <h1> to <h6> tags:
<h1> defines the most important heading. <h6> defines the least important heading.
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>
11
Example
<p>This is<br>a para<br>graph with line breaks</p>
HTML Links
HTML links are defined with the <a> tag:
Example
<a href="http://www.seymourcollege.sa.edu.au">This is a link</a>
HTML Images
HTML images are defined with the <img> tag.
The source file (src), alternative text (alt), and size (width and height) are provided
as attributes:
Example
<img src="seymour.jpg" alt="Seymour.sa.edu.au" width="104"height="142">
Example
12
<!DOCTYPE html>
<html>
<body>
<h2>Chocolate Cake</h2>
<img src="pic_chocolate cake.jpg" alt="Chocolate Cake"
style="width:304px;height:228px;">
</body>
</html>
Always specify the width and height of an image. If width and height are not
specified, the page will flicker while the image loads.
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>
13
Animated Images
The GIF standard allows animated images:
Example
<img src="programming.gif" alt="Computer Man"style="width:48px;height:48px;">
HTML Styles
HTML Styling
Every HTML element has a default style (background color is white and text color is black).
Changing the default style of an HTML element, can be done with the style attribute.
This example changes the default background color from white to lightgrey:
Example
<body style="background-color:lightgrey">
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
Example
<h1 style="color:blue">This is a heading</h1>
<p style="color:red">This is a paragraph.</p>
Hexadecimal colors
RGB colors
Color names
14
Hexadecimal Colors
Hexadecimal colour values are supported in all major browsers.
A hexadecimal colour is specified with: #RRGGBB, where the RR (red), GG (green) and BB
(blue) hexadecimal integers specify the components of the colou
r. All values must be between 00 and FF.
For example, the #0000FF value is rendered as blue, because the blue component is set to
its highest value (FF) and the others are set to the lowest value (00).
RGB Colours
RGB colour values are supported in all major browsers.
An RGB colour value is specified with: rgb(red, green, blue). Each parameter (red, green,
and blue) defines the intensity of the color and can be an integer between 0 and 255.
For example, the rgb(0,0,255) value is rendered as blue, because the blue parameter is set
to its highest value (255) and the others are set to 0.
Colour Names
All major browsers also support 140 standard color names.
HTML Fonts
The font-family property defines the font to be used for an HTML element:
Example
<h1 style="font-family:verdana">This is a heading</h1>
<p style="font-family:courier">This is a paragraph.</p>
15
Example
<h1 style="font-size:300%">This is a heading</h1>
<p style="font-size:160%">This is a paragraph.</p>
Example
<h1 style="text-align:center">Centered Heading</h1>
<p>This is a paragraph.</p>
16
Bold text
Important text
Italic text
Emphasized text
Marked text
Small text
Deleted text
Inserted text
Subscripts
Superscripts
Example
<p>This text is normal.</p>
<p><b>This text is bold</b>.</p>
The HTML <strong> element defines strong text, with added semantic "strong"
importance.
Example
<p>This text is normal.</p>
<p><strong>This text is strong</strong>.</p>
17
Example
<p>This text is normal.</p>
<p><i>This text is italic</i>.</p>
18
HTML Tables
HTML Table Example
Example explained:
Tables are defined with the <table> tag.
Tables are divided into table rows with the <tr> tag.
Table rows are divided into table data with the <td> tag.
A table row can also be divided into table headings with the <th> tag.
19
Example
<table border="1" 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>
</table>
Remember to define borders for both the table and the table cells.
20
Example
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Points</th>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
To left-align the table headings, use the CSS text-align property:
Example
th {
text-align: left;
}
Example
table {
border-spacing: 5px;
}
21
HTML Lists
22
Example
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Disc:
<ul style="list-style-type:disc">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Circle:
<ul style="list-style-type:circle">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
23
Square:
<ul style="list-style-type:square">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Example
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
24
Numbers:
<ol type="1">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
Uppercase Letters:
<ol type="A">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
Lowercase Letters:
<ol type="a">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
25
Example
<dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold drink</dd>
</dl>
Example
<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.
26
Horizontal Lists
HTML lists can be styled in many different ways with CSS.
One popular way, is to style a list to be displayed horizontally:
Example
<!DOCTYPE html>
<html>
<head>
<style>
ul#menu li {
display:inline;
}
</style>
</head>
<body>
<h2>Horizontal List</h2>
<ul id="menu">
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
<li>PHP</li>
</ul>
</body>
</html>
27
Block-level Elements
A block-level element always starts on a new line and takes up the full width available
(stretches out to the left and right as far as it can).
The <div> element is a block-level element.
<div>
<h1> - <h6>
<p>
<form>
28
Inline Elements
An inline element does not start on a new line and only takes up as much width as
necessary.
This is an inline <span> element inside a paragraph.
Examples of inline elements:
<span>
<a>
<img>
Example
<div style="background-color:black; color:white; 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>
</div>
Example
<h1>My <span style="color:red">Important</span> Heading</h1>
30
London
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.
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.
Paris
Paris is the capital and most populous city of France.
Situated on the Seine River, it is at the heart of the le-de-France region, also known as the
rgion parisienne.
Within its metropolitan area is one of the largest population centers in Europe, with over 12
million inhabitants.
Tokyo
Tokyo is the capital of Japan, the center of the Greater Tokyo Area, and the most populous
metropolitan area in the world.
It is the seat of the Japanese government and the Imperial Palace, and the home of the
Japanese Imperial Family.
The Tokyo prefecture is part of the world's most populous metropolitan area with 38 million
people and the world's largest urban economy.
31
Example
<!DOCTYPE html>
<html>
<head>
<style>
div.cities {
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>
</div>
<div class="cities">
<h2>Paris</h2>
<p>Paris is the capital and most populous city of France.</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>
</div>
</body>
</html>
32