HTML Tutorial

Download as pdf or txt
Download as pdf or txt
You are on page 1of 31

HTML Basics

HTML
Introduction to HTML
HTML

HTML is a language for describing web pages.

• HTML stands for Hyper Text Markup Language

• HTML is not a programming language, it is a markup language

• A markup language is a set of markup tags

• The markup tags describe how text should be displayed by a web browser

HTML Markup Tags

• HTML tags are markup codes surrounded by 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

HTML File

• An HTML file is a text file with markup tags

• An HTML file must have an htm or html file extension

• An HTML file can be created using a simple text editor

• An HTML file is often called an HTML document or a web page

When a browser displays a web page, it will not display the markup tags. The browser
uses the markup tags to understand the layout of the page.

An HTML Document

<html>
<body>
<p>This is my first paragraph</p>
<p>This is my <b>second</b> paragraph</p>
</body>
</html>

Department of Computer Science and Engineering Cape Institute of Technology


HTML Basics

HTML Elements
HTML documents are text files made up of HTML elements.

HTML elements are defined using HTML tags.

HTML Tags

• HTML tags are used to mark-up HTML elements

• HTML tags are surrounded by the two characters < and >

• The surrounding characters are called angle brackets

• 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 text between the start and end tags is the element content

• HTML tags are not case sensitive, <b> means the same as <B>

HTML Elements

This is an HTML element:

<b>This text is bold</b>

The HTML element starts with a start tag: <b>


The content of the HTML element is: This text is bold
The HTML element ends with an end tag: </b>

The purpose of the <b> tag is to define an HTML element that should be displayed as
bold.

This is also an HTML element:

<body>
This is my first homepage. <b>This text is bold</b>
</body>

This HTML element starts with the start tag <body>, and ends with the end tag </body>.

The purpose of the <body> tag is to define the HTML element that contains the body of
the HTML document.

Department of Computer Science and Engineering Cape Institute of Technology


HTML Basics

Basic HTML Tags


Headings

Headings are defined with the <h1> to <h6> tags. <h1> defines the largest heading. <h6>
defines the smallest heading.

<h1>This is a heading</h1>

<h2>This is a heading</h2>

<h3>This is a heading</h3>

<h4>This is a heading</h4>

<h5>This is a heading</h5>

<h6>This is a heading</h6>

HTML automatically adds an extra blank line before and after a heading.

Paragraphs

Paragraphs are defined with the <p> tag.

<p>This is a paragraph</p>

<p>This is another paragraph</p>

HTML automatically adds an extra blank line before and after a paragraph.

Line Breaks

The <br> tag is used when you want to break a line, but don't want to start a new
paragraph. The <br> tag forces a line break wherever you place it.

<p>This <br> is a para<br>graph with line breaks</p>

Comments in HTML

The comment tag is used to insert a comment in the HTML source code. A comment will
be ignored by the browser.

Department of Computer Science and Engineering Cape Institute of Technology


HTML Basics

<!-- This is a comment -->

Basic HTML Tags

Tag Description
<html> Defines an HTML document
<body> Defines the document's body
<h1> to <h6> Defines header 1 to header 6
<p> Defines a paragraph
<br> Inserts a single line break
<hr> Defines a horizontal rule
<!--> Defines a comment

HTML Attributes
HTML Tag Attributes

HTML tags can have attributes. Attributes provide additional information to an HTML
element.

Attributes always come in name/value pairs like this: name="value".

Attributes are always specified in the start tag of an HTML element.

Attributes Example 1:

<h1> defines the start of a heading.

<h1 align="center"> has additional information about the alignment.

Attributes Example 2:

<body> defines the body of an HTML document.

<body bgcolor="yellow"> has additional information about the background color.

Department of Computer Science and Engineering Cape Institute of Technology


HTML Basics

Attributes Example 3:

<table> defines an HTML table. (You will learn more about HTML tables later)

<table border="1"> has additional information about the border around the table.

Always Quote Attribute Values

Attribute values should always be enclosed in quotes. Double style quotes are the most
common, but single style quotes are also allowed.

In some rare situations, like when the attribute value itself contains quotes, it is necessary
to use single quotes:

name='John "ShotGun" Nelson'

HTML Text Formatting


HTML defines a lot of elements for formatting output, like bold or italic text.

Text Formatting Tags

Tag Description
<b> Defines bold text
<big> Defines big text
<em> Defines emphasized text
<i> Defines italic text
<small> Defines small text
<strong> Defines strong text
<sub> Defines subscripted text
<sup> Defines superscripted text
<ins> Defines inserted text
<del> Defines deleted text
<s> Deprecated. Use <del> instead
<strike> Deprecated. Use <del> instead

Department of Computer Science and Engineering Cape Institute of Technology


HTML Basics

<u> Deprecated. Use styles instead

"Computer Output" Tags

Tag Description
<code> Defines computer code text
<kbd> Defines keyboard text
<samp> Defines sample computer code
<tt> Defines teletype text
<var> Defines a variable
<pre> Defines preformatted text
<listing> Deprecated. Use <pre> instead
<plaintext> Deprecated. Use <pre> instead
<xmp> Deprecated. Use <pre> instead

Citations, Quotations, and Definition Tags

Tag Description
<abbr> Defines an abbreviation
<acronym> Defines an acronym
<address> Defines an address element
<bdo> Defines the text direction
<blockquote> Defines a long quotation
<q> Defines a short quotation
<cite> Defines a citation
<dfn> Defines a definition term

HTML Character Entities


Reserved characters in HTML must be replaced with character entities.

Department of Computer Science and Engineering Cape Institute of Technology


HTML Basics

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.

A character entity looks like this: &entity_name; OR &#entity_number;

To display a less than sign we must write: &lt; or &#60;

Non-breaking Space

The most common character entity in HTML is the 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 &nbsp;
character entity.

Commonly Used Character Entities

Result Description Entity Name Entity Number


non-breaking space &nbsp; &#160;
< less than &lt; &#60;
> greater than &gt; &#62;
& ampersand &amp; &#38;
¢ cent &cent; &#162;
£ pound &pound; &#163;
¥ yen &yen; &#165;
€ euro &euro; &#8364;
§ section &sect; &#167;
© copyright &copy; &#169;
® registered trademark &reg; &#174;

Note: Entity names are case sensitive!

Department of Computer Science and Engineering Cape Institute of Technology


HTML Basics

HTML Links
HTML uses a hyperlink to link to another document on the Web.

The Anchor Tag and the Href Attribute

HTML uses the <a> (anchor) tag to create a link to another document.

An anchor can point to any resource on the Web: an HTML page, an image, a sound file,
a movie, etc.

The syntax of creating an anchor:

<a href="url">Text to be displayed</a>

The <a> tag is used to create an anchor to link from, the href attribute is used to address
the document to link to, and the words between the open and close of the anchor tag will
be displayed as a hyperlink.

This anchor defines a link to W3Schools:

<a href="http://www.w3schools.com/">Visit W3Schools!</a>

The line above will look like this in a browser:

Visit W3Schools!

The Target Attribute

With the target attribute, you can define where the linked document will be opened.

The line below will open the document in a new browser window:

<a href="http://www.w3schools.com/"
target="_blank">Visit W3Schools!</a>

The Anchor Tag and the Name Attribute

The name attribute is used to create a named anchor. When using named anchors we can
create links that can jump directly into a specific section on a page, instead of letting the
user scroll around to find what he/she is looking for.

Below is the syntax of a named anchor:

<a name="label">Text to be displayed</a>

Department of Computer Science and Engineering Cape Institute of Technology


HTML Basics

The name attribute is used to create a named anchor. The name of the anchor can be any
text you care to use.

The line below defines a named anchor:

<a name="tips">Useful Tips Section</a>

To link directly to the "tips" section, add a # sign and the name of the anchor to the end of
a URL, like this:

<a href="http://www.w3schools.com/html_links.asp#tips">

Jump to the Useful Tips Section</a>

Link Tags

Tag Description
<a> Defines an anchor

HTML Frames
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

• 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

• 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

Department of Computer Science and Engineering Cape Institute of Technology


HTML Basics

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%,*").

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 Tables
Tables

Tables are defined with the <table> tag. A table is divided into rows (with the <tr> tag),
and each row is divided into data cells (with the <td> tag). The letters td stands for "table
data," which is the content of a data cell. A data cell can contain text, images, lists,
paragraphs, forms, horizontal rules, tables, etc.

<table border="1">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>

Department of Computer Science and Engineering Cape Institute of Technology


HTML Basics

How it looks in a browser:

row 1, cell 1 row 1, cell 2

row 2, cell 1 row 2, cell 2

Tables and the Border Attribute

If you do not specify a border attribute the table will be displayed without any borders.
Sometimes this can be useful, but most of the time, you want the borders to show.

To display a table with borders, you will have to use the border attribute:

<table border="1">
<tr>
<td>Row 1, cell 1</td>
<td>Row 1, cell 2</td>
</tr>
</table>

Headings in a Table

Headings in a table are defined with the <th> tag.

<table border="1">
<tr>
<th>Heading</th>
<th>Another Heading</th>
</tr>
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>

Department of Computer Science and Engineering Cape Institute of Technology


HTML Basics

How it looks in a browser:

Heading Another Heading

row 1, cell 1 row 1, cell 2

row 2, cell 1 row 2, cell 2

Empty Cells in a Table

Table cells with no content are not displayed very well in most browsers.

<table border="1">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td></td>
</tr>
</table>

How it looks in a browser:

row 1, cell 1 row 1, cell 2

row 2, cell 1

Note that the borders around the empty table cell are missing (NB! Mozilla Firefox
displays the border).

To avoid this, add a non-breaking space (&nbsp;) to empty data cells, to make the borders
visible:

<table border="1">
<tr>
<td>row 1, cell 1</td>

Department of Computer Science and Engineering Cape Institute of Technology


HTML Basics

<td>row 1, cell 2</td>


</tr>
<tr>
<td>row 2, cell 1</td>
<td>&nbsp;</td>
</tr>
</table>

How it looks in a browser:

row 1, cell 1 row 1, cell 2

row 2, cell 1

Table Tags

Tag Description
<table> Defines a table
<th> Defines a table header
<tr> Defines a table row
<td> Defines a table cell
<caption> Defines a table caption
<colgroup> Defines groups of table columns
<col> Defines the attribute values for one or more columns in a table
<thead> Defines a table head
<tbody> Defines a table body
<tfoot> Defines a table footer

Department of Computer Science and Engineering Cape Institute of Technology


HTML Basics

HTML Lists
HTML supports ordered, unordered and definition lists.

Unordered Lists

An unordered list is a list of items. The list items are marked with bullets (typically small
black circles).

An unordered list starts with the <ul> tag. Each list item starts with the <li> tag.

<ul>
<li>Coffee</li>
<li>Milk</li>
</ul>

Here is how it looks in a browser:

• Coffee
• Milk

Inside a list item you can put paragraphs, line breaks, images, links, other lists, etc.

Ordered Lists

An ordered list is also a list of items. The list items are marked with numbers.

An ordered list starts with the <ol> tag. Each list item starts with the <li> tag.

<ol>
<li>Coffee</li>
<li>Milk</li>
</ol>

Here is how it looks in a browser:

1. Coffee
2. Milk

Inside a list item you can put paragraphs, line breaks, images, links, other lists, etc.

Definition Lists

A definition list is not a list of items. This is a list of terms and explanation of the terms.

Department of Computer Science and Engineering Cape Institute of Technology


HTML Basics

A definition list starts with the <dl> tag. Each definition-list term starts with the <dt> tag.
Each definition-list definition starts with the <dd> tag.

<dl>
<dt>Coffee</dt>
<dd>Black hot drink</dd>
<dt>Milk</dt>
<dd>White cold drink</dd>
</dl>

Here is how it looks in a browser:

Coffee
Black hot drink
Milk
White cold drink

Inside a definition-list definition (the <dd> tag) you can put paragraphs, line breaks,
images, links, other lists, etc.

List Tags

Tag Description
<ol> Defines an ordered list
<ul> Defines an unordered list
<li> Defines a list item
<dl> Defines a definition list
<dt> Defines a definition term
<dd> Defines a definition description
<dir> Deprecated. Use <ul> instead
<menu> Deprecated. Use <ul> instead

HTML Forms and Input


Department of Computer Science and Engineering Cape Institute of Technology
HTML Basics

HTML Forms are used to select different kinds of user input.

Forms

A form is an area that can contain form elements.

Form elements are elements that allow the user to enter information (like text fields,
textarea fields, drop-down menus, radio buttons, checkboxes, etc.) in a form.

A form is defined with the <form> tag.

<form>
<input>
<input>
</form>

Input

The most used form tag is the <input> tag. The type of input is specified with the type
attribute. The most commonly used input types are explained below.

Text Fields

Text fields are used when you want the user to type letters, numbers, etc. in a form.

<form>
First name:
<input type="text" name="firstname">
<br>
Last name:
<input type="text" name="lastname">
</form>

How it looks in a browser:

First name:
Last name:

Note that the form itself is not visible. Also note that in most browsers, the width of the
text field is 20 characters by default.

Department of Computer Science and Engineering Cape Institute of Technology


HTML Basics

Radio Buttons

Radio Buttons are used when you want the user to select 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 it looks in a browser:

Male
Female

Note that only one option can be chosen.

Checkboxes

Checkboxes are used when you want the user to select one or more options of a limited
number of choices.

<form>
I have a bike:
<input type="checkbox" name="vehicle" value="Bike">
<br>
I have a car:
<input type="checkbox" name="vehicle" value="Car">
<br>
I have an airplane:
<input type="checkbox" name="vehicle" value="Airplane">
</form>

How it looks in a browser:

I have a bike:
I have a car:
I have an airplane:

Department of Computer Science and Engineering Cape Institute of Technology


HTML Basics

The Form's Action Attribute and the Submit Button

When the user clicks on the "Submit" button, the content of the form is sent to the server.
The form's action attribute defines the name of the file to send the content to. The file
defined in the action attribute usually does something with the received input.

<form name="input" action="html_form_submit.asp"


method="get">
Username:
<input type="text" name="user">
<input type="submit" value="Submit">
</form>

How it looks in a browser:

Submit
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 "html_form_submit.asp". The page will
show you the received input.

Form Tags

Tag Description
<form> Defines a form for user input
<input> Defines an input field
<textarea> Defines a text-area (a multi-line text input control)
<label> Defines a label to a control
<fieldset> Defines a fieldset
<legend> Defines a caption for a fieldset
<select> Defines a selectable list (a drop-down box)
<optgroup> Defines an option group
<option> Defines an option in the drop-down box
<button> Defines a push button
<isindex> Deprecated. Use <input> instead

Department of Computer Science and Engineering Cape Institute of Technology


HTML Basics

HTML Images
With HTML you can display images in a document.

The Image Tag and the Src Attribute

In HTML, images are defined with the <img> tag.

The <img> tag is empty, which means that it contains attributes only and it 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 on your page.

The syntax of defining an image:

<img src="url">

The URL points to the location where the image is stored.

The Alt Attribute

The alt attribute is used to define an "alternate text" for an image. The value of the alt
attribute is an author-defined text:

<img src="boat.gif" alt="Big Boat">

The "alt" attribute tells the reader what he or she is missing on a page if the browser can't
load images. The browser will then display the alternate text instead of the image.

Image Tags

Tag Description
<img> Defines an image
<map> Defines an image map
<area> Defines a clickable area inside an image map

HTML Backgrounds
A good background can make a Web site look really great.

Department of Computer Science and Engineering Cape Institute of Technology


HTML Basics

Backgrounds

The <body> tag has two attributes where you can specify backgrounds. The background
can be a color or an image.

Bgcolor

The bgcolor attribute specifies a background-color for an HTML page. The value of this
attribute can be a hexadecimal number, an RGB value, or a color name:

<body bgcolor="#000000">
<body bgcolor="rgb(0,0,0)">
<body bgcolor="black">

The lines above all set the background-color to black.

Background

The background attribute specifies a background-image for an HTML page. The value of
this attribute is the URL of the image you want to use. If the image is smaller than the
browser window, the image will repeat itself until it fills the entire browser window.

<body background="clouds.gif">
<body background="http://www.w3schools.com/clouds.gif">

The URL can be relative (as in the first line above) or absolute (as in the second line
above).

HTML Colors
Colors are displayed combining RED, GREEN, and BLUE light sources.

Color Values

HTML colors can be defined as a hexadecimal notation for the combination of Red,
Green, and Blue color values (RGB).

The lowest value that can be given to one light source is 0 (hex #00) and the highest
value is 255 (hex #FF).

The table below shows the result of combining Red, Green, and Blue light sources:

Color Color HEX Color RGB

Department of Computer Science and Engineering Cape Institute of Technology


HTML Basics

#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)

W3C Standard Color Names

W3C has listed 16 color names that will validate with an HTML validator.

The color names are: aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive,
purple, red, silver, teal, white, and yellow.

HTML Color Names


HTML Color Names

The table below provides a list of the color names that are supported by all major
browsers.

Color Name Color HEX Color


AliceBlue #F0F8FF
AntiqueWhite #FAEBD7
Aqua #00FFFF
Aquamarine #7FFFD4
Azure #F0FFFF
Beige #F5F5DC
Bisque #FFE4C4

Department of Computer Science and Engineering Cape Institute of Technology


HTML Basics

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
DarkGrey #A9A9A9
DarkGreen #006400
DarkKhaki #BDB76B
DarkMagenta #8B008B
DarkOliveGreen #556B2F
Darkorange #FF8C00
DarkOrchid #9932CC
DarkRed #8B0000
DarkSalmon #E9967A

Department of Computer Science and Engineering Cape Institute of Technology


HTML Basics

DarkSeaGreen #8FBC8F
DarkSlateBlue #483D8B
DarkSlateGray #2F4F4F
DarkSlateGrey #2F4F4F
DarkTurquoise #00CED1
DarkViolet #9400D3
DeepPink #FF1493
DeepSkyBlue #00BFFF
DimGray #696969
DimGrey #696969
DodgerBlue #1E90FF
FireBrick #B22222
FloralWhite #FFFAF0
ForestGreen #228B22
Fuchsia #FF00FF
Gainsboro #DCDCDC
GhostWhite #F8F8FF
Gold #FFD700
GoldenRod #DAA520
Gray #808080
Grey #808080
Green #008000
GreenYellow #ADFF2F
HoneyDew #F0FFF0
HotPink #FF69B4
IndianRed #CD5C5C
Indigo #4B0082

Department of Computer Science and Engineering Cape Institute of Technology


HTML Basics

Ivory #FFFFF0
Khaki #F0E68C
Lavender #E6E6FA
LavenderBlush #FFF0F5
LawnGreen #7CFC00
LemonChiffon #FFFACD
LightBlue #ADD8E6
LightCoral #F08080
LightCyan #E0FFFF
LightGoldenRodYellow #FAFAD2
LightGray #D3D3D3
LightGrey #D3D3D3
LightGreen #90EE90
LightPink #FFB6C1
LightSalmon #FFA07A
LightSeaGreen #20B2AA
LightSkyBlue #87CEFA
LightSlateGray #778899
LightSlateGrey #778899
LightSteelBlue #B0C4DE
LightYellow #FFFFE0
Lime #00FF00
LimeGreen #32CD32
Linen #FAF0E6
Magenta #FF00FF
Maroon #800000
MediumAquaMarine #66CDAA

Department of Computer Science and Engineering Cape Institute of Technology


HTML Basics

MediumBlue #0000CD
MediumOrchid #BA55D3
MediumPurple #9370D8
MediumSeaGreen #3CB371
MediumSlateBlue #7B68EE
MediumSpringGreen #00FA9A
MediumTurquoise #48D1CC
MediumVioletRed #C71585
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 #D87093
PapayaWhip #FFEFD5
PeachPuff #FFDAB9
Peru #CD853F

Department of Computer Science and Engineering Cape Institute of Technology


HTML Basics

Pink #FFC0CB
Plum #DDA0DD
PowderBlue #B0E0E6
Purple #800080
Red #FF0000
RosyBrown #BC8F8F
RoyalBlue #4169E1
SaddleBrown #8B4513
Salmon #FA8072
SandyBrown #F4A460
SeaGreen #2E8B57
SeaShell #FFF5EE
Sienna #A0522D
Silver #C0C0C0
SkyBlue #87CEEB
SlateBlue #6A5ACD
SlateGray #708090
SlateGrey #708090
Snow #FFFAFA
SpringGreen #00FF7F
SteelBlue #4682B4
Tan #D2B48C
Teal #008080
Thistle #D8BFD8
Tomato #FF6347
Turquoise #40E0D0
Violet #EE82EE

Department of Computer Science and Engineering Cape Institute of Technology


HTML Basics

Wheat #F5DEB3
White #FFFFFF
WhiteSmoke #F5F5F5
Yellow #FFFF00
YellowGreen #9ACD32

HTML Styles
How to Use Styles

When a browser reads a style sheet, it will format the document according to it. There are
three ways of inserting a style sheet:

External 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>

Internal Style Sheet

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>

Department of Computer Science and Engineering Cape Institute of Technology


HTML Basics

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:

<p style="color: red; margin-left: 20px">


This is a paragraph
</p>

Style Tags

Tag Description
<style> Defines a style definition
<link> Defines a resource reference
<div> Defines a section in a document
<span> Defines a section in a document
<font> Deprecated. Use styles instead
<basefont> Deprecated. Use styles instead
<center> Deprecated. Use styles instead

Summary
HTML Basic Document

<html>
<head>
<title>Document name goes here</title>
</head>

<body>
Visible text goes here
</body>

</html>

Department of Computer Science and Engineering Cape Institute of Technology


HTML Basics

Heading Elements

<h1>Largest Heading</h1>

<h2> . . . </h2>
<h3> . . . </h3>
<h4> . . . </h4>
<h5> . . . </h5>

<h6>Smallest Heading</h6>

Text Elements

<p>This is a paragraph</p>
<br> (line break)
<hr> (horizontal rule)
<pre>This text is preformatted</pre>

Logical Styles

<em>This text is emphasized</em>


<strong>This text is strong</strong>
<code>This is some computer code</code>

Physical Styles

<b>This text is bold</b>


<i>This text is italic</i>

Links, Anchors, and Image Elements

<a href="http://www.example.com/">This is a Link</a>


<a href="http://www.example.com/"><img src="URL" alt="Alternate Text"></a>
<a href="mailto:[email protected]">Send e-mail</a>

A named anchor:
<a name="tips">Useful Tips Section</a>
<a href="#tips">Jump to the Useful Tips Section</a>

Unordered list

<ul>
<li>First item</li>
<li>Next item</li>
</ul>

Department of Computer Science and Engineering Cape Institute of Technology


HTML Basics

Ordered list

<ol>
<li>First item</li>
<li>Next item</li>
</ol>

Definition list

<dl>
<dt>First term</dt>
<dd>Definition</dd>
<dt>Next term</dt>
<dd>Definition</dd>
</dl>

Tables

<table border="1">
<tr>
<th>someheader</th>
<th>someheader</th>
</tr>
<tr>
<td>sometext</td>
<td>sometext</td>
</tr>
</table>

Frames

<frameset cols="25%,75%">
<frame src="page1.htm">
<frame src="page2.htm">
</frameset>

Forms

<form action="http://www.example.com/test.asp" method="post/get">

<input type="text" name="lastname" value="Nixon" size="30" maxlength="50">


<input type="password">
<input type="checkbox" checked="checked">

Department of Computer Science and Engineering Cape Institute of Technology


HTML Basics

<input type="radio" checked="checked">


<input type="submit">
<input type="reset">
<input type="hidden">

<select>
<option>Apples
<option selected>Bananas
<option>Cherries
</select>

<textarea name="Comment" rows="60" cols="20"></textarea>

</form>

Entities

&lt; is the same as <


&gt; is the same as >
&#169; is the same as ©

Other Elements

<!-- This is a comment -->

<blockquote>
Text quoted from some source.
</blockquote>

<address>
Address 1<br>
Address 2<br>
City<br>
</address>

Department of Computer Science and Engineering Cape Institute of Technology

You might also like