Cape It Unit 2 Notes Mod 2 So 13 HTML PDF
Cape It Unit 2 Notes Mod 2 So 13 HTML PDF
Cape It Unit 2 Notes Mod 2 So 13 HTML PDF
Construct web pages Design, code, construct web pages using HTML,
authoring tools, Hyperlinks
Website: http://www.w3schools.com
http://www.html.am/
With our online HTML editor, you can edit the HTML, and click on a button to view the result.
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Example Explained
The DOCTYPE declaration defines the document type
The text between <html> and </html> describes the web page
The text between <body> and </body> is the visible page content
The text between <h1> and </h1> is displayed as a heading
The text between <p> and </p> is displayed as a paragraph
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>
HTML tags normally come in pairs like <b> and </b>
The first tag in a pair is the start tag, the second tag is the end tag
The end tag is written like the start tag, with a forward slash before the tag name
Start and end tags are also called opening tags and closing tags
<tagname>content</tagname>
But strictly speaking, an HTML element is everything between the start tag and the end tag, including
the tags:
HTML Element:
<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:
<html>
<body>
<h1>This a heading</h1>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
</body>
</html>
Adobe Dreamweaver
Microsoft Expression Web
CoffeeCup HTML Editor
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.
Start
All Programs
Accessories
Notepad
When you save an HTML file, you can use either the .htm or the .html file extension. There is no
difference, it is entirely up to you.
Example
<h1>This is a heading</h1>
<h2>This is a heading</h2>
<h3>This is a heading</h3>
Try it yourself »
HTML Paragraphs
HTML paragraphs are defined with the <p> tag.
Example
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
Try it yourself »
HTML Links
HTML links are defined with the <a> tag.
Example
<a href="http://www.w3schools.com">This is a link</a>
Try it yourself »
HTML Images
HTML images are defined with the <img> tag.
Example
<img src="w3schools.jpg" alt="W3Schools.com" width="104" height="142">
Try it yourself »
Cape IT UNIT 2 Mod 2 SO 13 – Web Page using HTML www.w3school.com 4
Note: The filename and the size of the image are provided as attributes.
HTML Elements
An HTML element is everything from the start tag to the end tag:
<br>
* The start tag is often called the opening tag. The end tag is often called the closing tag.
Tip: You will learn about attributes in the next chapter of this tutorial.
<body>
<p>This is my first paragraph.</p>
</body>
</html>
<body>
<p>This is my first paragraph.</p>
</body>
Cape IT UNIT 2 Mod 2 SO 13 – Web Page using HTML www.w3school.com 5
The <body> element defines the body of the HTML document.
The element has a start tag <body> and an end tag </body>.
The element content is another HTML element (a p element).
<html>
<body>
<p>This is my first paragraph.</p>
</body>
</html>
<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 .
<br> is an empty element without a closing tag (the <br> tag defines a line break).
Tip: In XHTML, all elements must be closed. Adding a slash inside the start tag, like <br />, is the
proper way of closing empty elements in XHTML (and XML).
W3Schools use lowercase tags because the World Wide Web Consortium
(W3C) recommends lowercase in HTML 4, and demands lowercase tags in XHTML.
HTML Attributes
HTML elements can have attributes
Attributes provide additional information about an element
Attributes are always specified in the start tag
Attributes come in name/value pairs like: name="value"
Attribute Example
HTML links are defined with the <a> tag. The link address is specified in the href attribute:
Example
Try it yourself »
Double style quotes are the most common, but single style quotes are also allowed.
Tip: In some rare situations, when the attribute value itself contains quotes, it is necessary to use single
quotes: name='John "ShotGun" Nelson'
However, the World Wide Web Consortium (W3C) recommends lowercase attributes/attribute values in
their HTML 4 recommendation.
Below is a list of some attributes that can be used on any HTML element:
Attribute Description
class Specifies one or more class names for an element (refers to a class in a style sheet)
<body style="background:#80BFFF">
<span style="color:#80BFFF">
<table style="background:#80BFFF">
Cape IT UNIT 2 Mod 2 SO 13 – Web Page using HTML www.w3school.com 7
Using HTML color code for link color:
<a style="color:#80BFFF">
http://www.html.am/html-codes/background-code/
Meaning of symbols:
The first two symbols in HTML color code represents the intensity of red color. 00 is the least and FF is the most
intense. The third and fourth represents intensity of green and fifth and sixth represents the intensity of blue. So
with combining the intensity of red, green and blue we can mix almost any color that our heart desire;)
Examples:
#FF0000 - With this HTML code we tell browser to show maximum of red and no green and no blue. The result is
of course pure red color:
#00FF00 - This HTML code shows just green and no red and blue. The result is:
#0000FF - This HTML code shows just blue and no red and green. The result is:
#CCEEFF - Take some red a bit more of green and maximum of blue to get color of sky:
http://html-color-codes.info/
Backgrounds for the Whole Page
To set the background properties for the whole page, simply apply the property/properties to the body element.
<html>
<head>
</head>
<body style="background-color:#eeeeee;">
</body>
http://www.quackit.com/html/codes/html_background_codes.cfm
<html>
<body style="background-color:#c0c0c0;"
Bacvg
<font color="green"><center><h1><font size="15"> SUZI'S FLOWER POT </h1></center>
</font></font size>
<body>
Scrolling Text
This page contains HTML code for creating scrolling text.
You can create scrolling text in HTML using <marquee> tags. You can make your text scroll from right to left. You can make it
scroll left to right. You can make it bounce back and forth. You can make it scroll up or down. You can even make your text zoom
in from the side and stay in the same place.
Usability of Marquees
You should be careful when using marquees in HTML. Many web users dislike websites that contain scrolling text and other
elements, so try to use them tastefully :)
Also note that the <marquee> tag is not part of the official HTML specification. Having said that, it is recognized by most major
browsers.
http://www.html.am/html-codes/marquees/scrolling-text.cfm
HTML Paragraphs
Paragraphs are defined with the <p> tag.
Example
<p>This is a paragraph</p>
<p>This is another paragraph</p>
Try it yourself »
Note: Browsers automatically add an empty line before and after a paragraph.
Example
<p>This is a paragraph
<p>This is another paragraph
Try it yourself »
The example above will work in most browsers, but don't rely on it. Forgetting the end tag can produce
unexpected results or errors.
Note: Future version of HTML will not allow you to skip end tags.
Example
<p>This is<br>a para<br>graph with line breaks</p>
Try it yourself »
With HTML, you cannot change the output by adding extra spaces or extra lines in your HTML code.
Cape IT UNIT 2 Mod 2 SO 13 – Web Page using HTML www.w3school.com 10
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.
Try it yourself
Line breaks
The use of line breaks in an HTML document.
Poem problems
Some problems with HTML formatting.
More Examples
More paragraphs
The default behaviors of paragraphs.
Tag Description
superscript
This is subscript and
Try it yourself »
These HTML tags are called formatting tags (look at the bottom of this page for a complete reference).
<strong> or <em> means that you want the text to be rendered in a way that the user understands as
Preformatted text
How to control the line breaks and spaces with the pre tag.
Address
How to define contact information for the author/owner of an HTML document.
Text direction
How to change the text direction.
Quotations
How to handle long and short quotations.
Marked/Highlighted text
How to mark/highlight text.
Note: There is an exclamation point (!) in the opening tag, but not in the closing tag.
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>
Try it yourself »
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">
-->
Try it yourself »
For example the <!--webbot bot--> tags which are wrapped inside HTML comments by FrontPage.
Conditional comments enable you to add a browser specific code that executes only if the browser is IE
but is treated as a comment by other browsers.
You can add conditional comments to your HTML document by using the following syntax:
Example
<!--[if IE 5]>This is IE 5<br><![endif]-->
<!--[if IE 6]>This is IE 6<br><![endif]-->
<!--[if IE 7]>This is IE 7<br><![endif]-->
<!--[if IE 8]>This is IE 8<br><![endif]-->
<!--[if IE 9]>This is IE 9<br><![endif]-->
A hyperlink (or link) is a word, group of words, or image that you can click on to jump to another
document.
When you move the cursor over a link in a Web page, the arrow will turn into a little hand.
The most important attribute of the <a> element is the href attribute, which indicates the link's
destination.
Example
<a href="http://www.w3schools.com/">Visit W3Schools</a>
Tip: The "Link text" doesn't have to be text. It can be an image or any other HTML element.
The example below will open the linked document in a new browser window or a new tab:
Example
<a href="http://www.w3schools.com/" target="_blank">Visit W3Schools!</a>
Tip: Bookmarks are not displayed in any special way. They are invisible to the reader.
Example
An anchor with an id inside an HTML document:
Create a link to the "Useful Tips Section" inside the same document:
Or, create a link to the "Useful Tips Section" from another page:
<a href="http://www.w3schools.com/html_links.htm#tips">
Visit the Useful Tips Section</a>
Try it yourself »
The <img> tag is empty, which means that it contains attributes only, and has no closing tag.
To display an image on a page, you need to use the src attribute. Src stands for "source". The value of
the src attribute is the URL of the image you want to display.
The URL points to the location where the image is stored. An image named "boat.gif", located in the
"images" directory on "www.w3schools.com" has the URL: http://www.w3schools.com/images/boat.gif.
The browser displays the image where the <img> tag occurs in the document. If you put an image tag
between two paragraphs, the browser shows the first paragraph, then the image, and then the second
paragraph.
The alt attribute provides alternative information for an image if a user for some reason cannot view it
(because of slow connection, an error in the src attribute, or if the user uses a screen reader).
Tip: It is a good practice to specify both the height and width attributes for an image. If these
attributes are set, the space required for the image is reserved when the page is loaded. However,
without these attributes, the browser does not know the size of the image. The effect will be that the
page layout will change during loading (while the images load).
Note: When a web page is loaded, it is the browser, at that moment, that actually gets the image from
a web server and inserts it into the page. Therefore, make sure that the images actually stay in the
same spot in relation to the web page, otherwise your visitors will get a broken link icon. The broken
link icon is shown if the browser cannot find the image.
Jill Smith 50
Eve Jackson 94
Adam Johnson 67
HTML Tables
Tables are defined with the <table> tag.
A table is divided into rows with the <tr> tag. (tr stands for table row)
A row is divided into data cells with the <td> tag. (td stands for table data)
A row can also be divided into headings with the <th> tag. (th stands for table heading)
The <td> elements can contain all sorts of HTML elements like text, images, lists, other tables, etc.
Example
<table style="width:300px">
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
Try it yourself »
Example
<table border="1" style="width:300px">
<tr>
<td>Jill</td>
Cape IT UNIT 2 Mod 2 SO 13 – Web Page using HTML www.w3school.com 17
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
Try it yourself »
However, the border attribute is on its way out of the HTML standard!
It is better to use CSS.
Example
<style>
table,th,td
{
border:1px solid black;
}
</style>
Try it yourself »
Remember to define borders for both the table and the table cells.
Example
<style>
table,th,td
{
border:1px solid black;
border-collapse:collapse
}
</style>
Try it yourself »
If you do not specify a padding, the table cells will be displayed without padding.
Example
th,td
{
padding:15px;
}
Try it yourself »
By default, all major browsers display table headings as bold and centered:
Example
<table style="width:300px">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Points</th>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
Try it yourself »
Example
th
{
text-align:left;
}
Try it yourself »
To set the cell spacing for the table, use the CSS border-spacing property:
Example
table
{
border-spacing:5px;
}
Try it yourself »
More Examples
Horizontal/Vertical table headings
How to create horizontal/vertical table headings.
<col> Specifies column properties for each column within a <colgroup> element
The most common HTML lists are ordered and unordered lists:
HTML Lists
Try-It-Yourself Examples
Unordered list
How to create an unordered list in an HTML document.
Ordered list
How to create an ordered list in an HTML document.
The list items are marked with bullets (typically small black circles).
<ul>
<li>Coffee</li>
<li>Milk</li>
</ul>
Coffee
Milk
<ol>
<li>Coffee</li>
<li>Milk</li>
</ol>
1. Coffee
2. Milk
The <dl> tag is used in conjunction with <dt> (defines terms/names) and <dd> (describes each
term/name):
<dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold drink</dd>
</dl>
Coffee
- black hot drink
Milk
- white cold drink
More Examples
Different types of ordered lists
Demonstrates different types of ordered lists.
Nested list
Demonstrates how you can nest lists.
Nested list 2
Demonstrates a more complicated nested list.
Description list
Demonstrates a definition list.
Color Values
CSS colors are defined using a hexadecimal (hex) notation for the combination of Red, Green, and Blue
color values (RGB). The lowest value that can be given to one of the light sources is 0 (hex 00). The
highest value is 255 (hex FF).
Hex values are written as 3 double digit numbers, starting with a # sign.
Color Examples
#000000 rgb(0,0,0)
#FF0000 rgb(255,0,0)
#00FF00 rgb(0,255,0)
#0000FF rgb(0,0,255)
#FFFF00 rgb(255,255,0)
#00FFFF rgb(0,255,255)
#FF00FF rgb(255,0,255)
#C0C0C0 rgb(192,192,192)
#FFFFFF rgb(255,255,255)
Try it yourself »
Most modern monitors are capable of displaying at least 16384 different colors.
If you look at the color table below, you will see the result of varying the red light from 0 to 255, while
keeping the green and blue light at zero.
To see a full list of color mixes when the red light varies from 0 to 255, click on one of the hex or rgb
values below.
#000000 rgb(0,0,0)
#100000 rgb(16,0,0)
#180000 rgb(24,0,0)
#200000 rgb(32,0,0)
#280000 rgb(40,0,0)
#300000 rgb(48,0,0)
#380000 rgb(56,0,0)
#400000 rgb(64,0,0)
#480000 rgb(72,0,0)
#500000 rgb(80,0,0)
#580000 rgb(88,0,0)
#600000 rgb(96,0,0)
#680000 rgb(104,0,0)
#700000 rgb(112,0,0)
#780000 rgb(120,0,0)
#800000 rgb(128,0,0)
#880000 rgb(136,0,0)
#900000 rgb(144,0,0)
#980000 rgb(152,0,0)
#A00000 rgb(160,0,0)
#A80000 rgb(168,0,0)
#B00000 rgb(176,0,0)
#B80000 rgb(184,0,0)
#C00000 rgb(192,0,0)
#C80000 rgb(200,0,0)
#D00000 rgb(208,0,0)
#D80000 rgb(216,0,0)
#E00000 rgb(224,0,0)
#E80000 rgb(232,0,0)
#F00000 rgb(240,0,0)
#F80000 rgb(248,0,0)
#FF0000 rgb(255,0,0)
Shades of Gray
Gray colors are displayed using an equal amount of power to all of the light sources. To make it easier
for you to select the right gray color we have compiled a table of gray shades for you:
#080808 rgb(8,8,8)
#101010 rgb(16,16,16)
#181818 rgb(24,24,24)
#202020 rgb(32,32,32)
#282828 rgb(40,40,40)
#303030 rgb(48,48,48)
#383838 rgb(56,56,56)
#404040 rgb(64,64,64)
#484848 rgb(72,72,72)
#505050 rgb(80,80,80)
#585858 rgb(88,88,88)
#606060 rgb(96,96,96)
#686868 rgb(104,104,104)
#707070 rgb(112,112,112)
#787878 rgb(120,120,120)
#808080 rgb(128,128,128)
#888888 rgb(136,136,136)
#909090 rgb(144,144,144)
#989898 rgb(152,152,152)
#A0A0A0 rgb(160,160,160)
#A8A8A8 rgb(168,168,168)
#B0B0B0 rgb(176,176,176)
#B8B8B8 rgb(184,184,184)
#C0C0C0 rgb(192,192,192)
#C8C8C8 rgb(200,200,200)
#D0D0D0 rgb(208,208,208)
#D8D8D8 rgb(216,216,216)
#E0E0E0 rgb(224,224,224)
#E8E8E8 rgb(232,232,232)
#F0F0F0 rgb(240,240,240)
#F8F8F8 rgb(248,248,248)
#FFFFFF rgb(255,255,255)
The 216 cross-browser color palette was created to ensure that all computers would display the colors
correctly when running a 256 color palette: