Professional Documents
Culture Documents
CONTENTS INCLUDE:
Core HTML
n
HTML Basics
n
HTML vs XHTML
n
Validation
n
Useful Open Source Tools
n
Page Structure Elements
n
Key Structural Elements and more... By Andy Harris
The src attribute describes where the image file can be found,
html Basics and the alt attribute describes alternate text that is displayed if
the image is unavailable.
HTML and XHTML are the foundation of all web development.
HTML is used as the graphical user interface in client-side Nested tags
programs written in JavaScript. Server-side languages like PHP Tags can be (and frequently are) nested inside each other. Tags
and Java also receive data from web pages and use HTML cannot overlap, so <a><b></a></b> is not legal, but <a><b></
as the output mechanism. The emerging Ajax technologies b></a> is fine.
processor, but in some type of editor that creates plain text. of XML. The same style guidelines are appropriate whether
Every page has a large container (HTML or XHTML) and you write in HTML or XHTML (but they tend to be enforced in
two major subcontainers, the head and the body. The head XHTML):
area contains information useful behind the scenes, such as
CSS formatting instructions and JavaScript code. The body • Use a doctype to describe the language (described below)
contains the part of the page that is visible to the user. • Write all code in lowercase letters
• Encase all attribute values in double quotes
Tags and Attributes • Each tag must have an end specified. This is normally
An HTML document is based on the notion of tags. A tag is a done with an ending tag, but a special case allows for
piece of text inside angle brackets (<>). Tags typically have a non-content tags.
beginning and an end, and usually contain some sort of text
Most of the requirements of XHTML turn out to be good
inside them. For example, a paragraph is normally denoted like
practice whether you write HTML or XHTML. I recommend
this:
<p>
This is my paragraph.
</p>
Get More Refcardz
(They’re free!)
The <p> indicates the beginning of a paragraph. Text is then
placed inside the tag, and the end of the paragraph is denoted n Authoritative content
by an end tag, which is similar to the start tag but with a slash n Designed for developers
(</p>.) It is common to indent content in a multi-line tag, but it n Written by top experts
is also legal to place tags on the same line: n Latest tools & technologies
<p>This is my paragraph.</p>
n Bonus content online
Tags are sometimes enhanced by attributes, which are name n New issue every 1-2 weeks
value pairs that modify the tag. For example, the <img> tag
(used to embed an image into a page) usually includes the
following attributes:
Subscribe Now for FREE!
<img src = “myPic.jpg” Refcardz.com
Alt = “this is my picture” />
using XHTML strict so you can validate your code and know it Web Developer https://www.addons.mozilla.org/en-US/firefox/addon/60 This Firefox
follows the strictest standards. Toolbar extension adds numerous debugging and web development tools to
your browser.
XHTML has a number of flavors. The strict type is Firebug https:addons.mozilla.org/en-US/firefox/addon/1843 is an add-on that
adds full debugging capabilities to the browser. The firebug lite version
recommended, as it is the most up-to-date standard which even works with IE.
will produce the most predictable results. You can also use
a transitional type (which allows deprecated HTML tags) and Page Structure Elements
a frameset type, which allows you to add frames. For most
applications, the strict type is preferred. The following elements are part of every web page.
HTML Template
Element Description
The following code can be copied and pasted to form the
<html></html> Surrounds the entire page
foundation of a basic web page:
<head></head> Contains header information (metadata, CSS styles, JavaScript
code)
<html>
<head> <title></title> Holds the page title normally displayed in the title bar and used
<title></title> in search results
</head>
<body></body> Contains the main body text. All parts of the page normally visible
<body> are in the body
</body>
</html>
Key Structural Elements
XHTML Template
The XHTML template is a bit more complex, so it’s common to
Most pages contain the following key structual elements:
keep a copy on your desktop for quick copy – and paste work,
or to define it as a starting template in your editor. Element Name Description
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” <h1></h1> Heading 1 Reserved fo strongest emphasis
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<h2></h2> Heading 2 Secondary level heading. Headings go down to level 6,
<html lang=”EN” dir=”ltr” xmlns=”http://www.w3.org/1999/xhtml”>
but <h1> through <h3> are most common
<head>
<meta http-equiv=”content-type” content=”text/xml; <p></p> Paragraph Most of the body of a page should be enclosed in
charset=utf-8” /> paragraphs
<title></title>
</head> <div></div> Division Similar to a paragraph, but normally marks a section of
a page. Divs usually contain paragraphs
<body>
</body>
</html> Lists and data
Validation
Web pages frequently incorporate structured data so HTML
includes several useful list and table tags:
The structure of your web pages is critical to the success of
programs based on those pages, so use a validating tool to Element Name Description
ensure you haven’t missed anything. <ul></ul> Unordered Normally these lists feature bullets (but that can be
list changed with CSS)
Validating Tool Description
<ol></ol> Ordered These usually are numbered, but this can be changed
WC3 The most commonly used validator is online at http://validator.w3.org This list with CSS
free tool checks your page against the doctype you specify and ensures
you are following the standards. This acts as a ‘spell-checker’ for your code <li></li> List item Used to describe a list item in an unordered list or an
and warns you if you made an error like forgetting to close a tag. ordered list
HTML Tidy There’s an outstanding free tool called HTML tidy which not only checks <dl></dl> Definition Used for lists with name-value pairs
your pages for validity, but also fixes most errors automatically. Download list
this tool at http://tidy.sourceforge.net/ or (better) use the HTML validator
extension to build tidy into your browser. <dt></dt> Definition The name in a name-value pair. Used in definition lists
term
HTML Validator The extension mechanism of Firefox makes it a critical tool for web
extension developers. The HTML Validator extension is an invaluable tool. It <dd></dd> Definition The value (or definition) of a name – value pair
automatically checks any page you view in your browser against both the description
w3 validation engine and tidy. It can instantly find errors, and repair them
<table></table> Table Defines beginning and end of a table
on the spot with tidy. With this free extension available at
http://users.skynet.be/mgueury/mozilla/, there’s no good reason not to <tr></tr> Table row Defines a table row. A table normally consists of several
validate your code. <tr> pairs (one per row)
<td></td> Table data Indicates data in a table cell. <td> tags occur within
<tr> (which occur within <table>)
Useful open source tools
<th></th> Table Indicates a table cell to be treated as a heading with
heading special formatting
Some of the best tools for web development are available
through the open source community at no cost at all. Consider Visit http://www.aharrisbooks.net/dzone/listTable.html for an
these application as part of your HTML toolkit: example. Use view source to see the XHTML code.
<code> Legend
The code format is used to manage pre-formatted text, You can add a legend inside a fieldset. This describes the
especially code listings. It is very similar to pre. purpose of the fieldset.
<code>
Label
while i < 10: A label is a special inline element that describes a particular
i += 1
print i field. A label can be paired with an input element by putting
</code> that element’s ID in the label’s for attribute.
<blockquote> Input
This tag is used to mark multi-line quotes. Frequently it is set The input element is a general purpose inline element. It is
off with special fonts and indentation through CSS. It is (not meant to be used inside a form, and it is the basis for several
surprisingly) a block-level tag. types of more specific input. The subtype is indicated by the
type attribute. Input elements usually include an id attribute
<blockquote>
Quoth the raven: (used for CSS and JavaScript identification) and / or a name
Nevermore attribute (used in server-side programming.) The same element
</blockquote>
can have both a name and an id.
<span>
The span tag is a vanilla inline tag. It has no particular Text
formatting of its own. It is intended to be used with a class or This element allows a single line of text input:
ID when you want to apply style to an inline chunk of code. <input type = “text”
id = “myText”
<span class = “highlight”>This text</span> will be highlighted. name = “myText” />
<em> Password
The em tag is used for standard emphasis. By default, <em> Passwords display just like textboxes, except rather than
italicizes text, but you can use CSS to make any other type of showing the text as it is typed, an asterisk appears for each
emphasis you wish. letter. Note that the data is not encoded in any meaningful way.
Typing text into a password field is still entirely unsecure.
<strong>
This tag represents strong emphasis. By default, it is bold, but you <input type = “password”
can modify the formatting with CSS. id = “myPWD” />
Radio Button
Forms Radio buttons are used in a group. Only one element of a radio
group can be selected at a time. Give all members of a radio
Forms are the standard user input mechanism in HTML / group the same name value to indicate they are part of a group.
XHTML. You will need another language like JavaScript or PHP <input type = “radio”
to read the contents of the form elements and act upon them. name = “radSize”
value = “small”
id = “radSmall”
Form Structure selected = “selected” />
A number of tags are used to describe the structure of the <label for = “radSmall”>Small</label>
<input type = “radio”
form. Begin by looking over a basic form: name = “radSize”
value = “large”
id = “radLarge” />
<form action = “”> <label for = “radLarge”>Large</label>
<fieldset>
<legend>My form</legend>
<label for = “txtName”>Name</label> Attaching a label to a radio button means the user can activate
<input type = “text”
id = “txtName” />
the button by clicking on the corresponding label. For best
<button type = “button” results, use the selected attribute to force one radio button to
Onclick = “doSomething()”>
Do something be the default.
</button>
</fieldset> Checkbox
</form>
Checkboxes are much like radio buttons, but they are
Form independent. Like radio buttons, they can be associated with a
The <form></form> pair describes the form. In XHTML strict, label.
you must indicate the form’s action property. This is typically
<input type = “checkbox”
the server-side program that will read the form. If there is no id = “chkFries” />
<label for = “chkFries”>Would you like fries with that?</label>
such program, you can set the action to null (“”) The method
attribute is used to determine whether the data is sent through Hidden
the get or post mechanism. Hidden fields hold data that is not visible to the user (although
Fieldset it is still visible in the code) It is primarily used to preserve state
Most form elements are inline tags, and must be encased in server-side programs.
in a block element. The fieldset is designed exactly for this
<input type = “hidden”
purpose. Its default appearance draws a box around the form. name = “txtHidden”
value = “recipe for secret sauce” />
You can have multiple fieldsets inside a single form.
Note that the data is still not protected in any meaningful way. size. Numerous CSS attributes replace this capability with much
more flexible alternatives. See the CSS refcard for details.
Button
Buttons are used to signal user input. Buttons can be created I (italics)
through the input tag: HTML code should indicate the level of emphasis rather
than the particular stylistic implications. Italicizing should
<input type = “button”
value = “launch the missiles”
be done through CSS. The <em> tag represents emphasized
onclick = “launchMissiles()” /> text. It produces italic output unless the style is changed to
something else. The <i> tag is no longer necessary and is not
This will create a button with the caption “launch the missiles.”
recommended. Add font-style: italic to the style of any element
When the button is clicked, the page will attempt to run a
that should be italicized.
JavaScript function called “launchMissiles()” Standard
buttons are usually used with JavaScript code on the client. B (bold)
The same button can also be created with this alternate format: Like italics, boldfacing is considered a style consideration. Use
the <strong> tag to denote any text that should be strongly
<button type = “button”
Onclick = “launchMissiles()”> emphasized. By default, this will result in boldfacing the
Launch the missiles enclosed text. You can add bold emphasis to any style with the
</button>
font-weight: bold attribute in CSS.
This second form is preferred because buttons often require
different CSS styles than other input elements. This second Deprecated techniques
form also allows an <img> tag to be placed inside the button,
making the image act as the button. In addition to the deprecated tags, there are also techniques
which were once common in HTML that are no longer
Reset
recommended.
The reset button automatically resets all elements in its form to
their default values. It doesn’t require any other attributes. Frames
Frames have been used as a layout mechanism and as a
<input type = “reset” />
<button type = “reset”> technique for keeping one part of the page static while
Reset dynamically loading other parts of the page in separate frames.
</button>
Use of frames has proven to cause major usability problems.
Select / option Layout is better handled through CSS techniques, and dynamic
Drop-down lists can be created through the select / option page generation is frequently performed through server-side
mechanism. The select tag creates the overall structure, which manipulation or AJAX.
is populated by option elements.
Table-based design
<select id = “selColor”> Before CSS became widespread, HTML did not have adequate
<option value = “#000000”>black</option>
<option value = “#FF0000”>red</option>
page formatting support. Clever designers used tables to
<option value = “#FFFFFF”>white</option> provide an adequate form of page layout. CSS provides a
</select>
much more flexible and powerful form of layout than tables,
The select has an id (for client-side code) or name (for server- and keeps the HTML code largely separated from the styling
side code) identifier. It contains a number of options. Each markup.
option has a value which will be returned to the program. The
text between <option> and </option> is the value displayed to HTML Entities
the user. In some cases (as in this example) the value displayed
to the user is not the same as the value used by programs.
Sometimes you need to display a special character in a web
Multiple Selections page. HTML has a set of special characters for exactly this
You can also create a multi-line selection with the select and purpose. Each of these entities begins with the ampersand(&)
option tags: followed by a code and a semicolon.
Certain tags common in older forms of HTML are no longer ® Registered trademark ® Registered trademark
recommended as CSS provides much better alternatives.
Font Numerous other HTML entities are available and can be found
The font tag was used to set font color, family (typeface) and in online resources like w3schools.
A B O U T t h e Au t h o r R E C O MM E N D E D B ook
Bro
ugh
t to
you
by...
Professional Cheat Sheets You Can Trust
tt erns “Exactly what busy developers need:
n Pa
ld
ona
sig son
McD
simple, short, and to the point.”
De
Ja
By
#8
ired
Insp e
by th
GoF ller con
tinu
ed
ndle
r doe
sn’t
have
to
in tab
Cha d ultip ecific o should cep pat
this if the m up the
man
n M
an ac
z.co
n
sp s ents
be a ject ime. d is see passed
Download Now
Com reter of ob at runt handle plem ks to de to
...
n
uest som tion proces e no m
Itera tor ore req
n A g in metho
d
cep
dm ndlin
e e ar
tho e to ptio th
Exce ion is sm to ha up th tered or
e ca
n
Ob
se Me S renc ral
Refcardz.com
plate RN refe listed in mp
le ce pt ni
echa n pa ssed co un avio
Beh
TTE
n
ex
is en
ick
Virtualization Windows Powershell
am
Tem Exa he .
A s has ack. W tion uest to ject
NP a qu s, a ct- cep Ob
it
n
st q
IG e s e rn b je call e ex e re
vid patt able O le th nd th
DES
! V is
pro s, hand s to ha
UT ard ign us ram .
des diag
ASP.NET MVC Framework Dependency Injection with EJB 3
ct
ABO refc oF) f Re le obje
erns ts o lass exa
mp oke
r
Patt ur (G lemen es c Inv
arz
n F o d rl d h
Des
ig go
f s: E inclu al w
o suc
Th is G a n
l 23 sign Pa
tt e rn e rn
patt , and a
re je ts
t ob mentin
c g AN
D
Oracle Berkeley DB Netbeans IDE JavaEditor
c
a h c M M
ef
in c u
orig kD
e
re.
Ea tion ons
tr ple CO ma
nd
boo Softwa rma to c their im om
Java Performance Tuning Getting Started with Eclipse
re R
( low
e x p o n la rg cute is al ch
ati an b rm ts. +exe . Th
bject nship
s su
Cre y c fo je c an o
t th
e
ed
to ob ms, d as ed rela
tio
Get
the
invo
catio
n.
DZone, Inc. ISBN-13: 978-1-934238-80-6
l Pa d respo ips and
ca y.
riant ling
ra o nsh pose the
re
uing
nalit
nctio led at va hand ing
cess be
140 Preston Executive Dr.
av io ,a n la ti P ur
as q
ue
ack
fu ject
pro
Beh nships t re ob
e
ISBN-10: 1-934238-80-5
nd the to
je c a n b callb b e ha eded. m ro nous nality ed
tio ob at c
ed
You ne s need
to ne
sts is couple
d fro
ynch nctio y ne
rela with s th st que
n
e th
e as the fu
itho
ut an is
eals
it
ship Reque y of re de ar
ld be litat pattern ssing w tation articul
e: D tion
Suite 100
faci
50795
or
e. Use
n
A hist shou d ce en p
rela ed to mman for pro implem ents its ting.
t S cop runtim s s to type Whe
n
e invo
ker
el y us e co
n
ue al le m pec
jec at cla Pro Th w id th
are utilizing a job q of the
ue ac tu
d im
p
ue is
ex
Ob ged with
n
C ues ueue e que
han eals me.
y dge enq
que s. B en to th
c roxy Job orithm be giv knowle that is terface
b e
cop
ss S at com
e : D
pile
ti
Deco
rato
r S
P
serv
er
Exa
mp
le g n
of al ed ca to have d obje of the
ut an nes
ct in
Cary, NC 27513
.com
Abst tory
C C
Fac
B
State
t
pte
r eigh y
teg
Ada Flyw Stra od
z
e rp rete plate
B ridg Inte Tem
S B B
er tor or
ww
C B r B
men
to
ject
Beh
avio
ral
Refcardz Feedback Welcome
d Me Ob
man B
S
Com
po si te
PO
ILIT
Y
succ
ess
or 9 781934 238806
ES
“DZone is a developer’s
CH
AIN
O
dream,” says PC Magazine.
FR
>>
Sponsorship Opportunities
ace
terf r
<<in andle
H st ( ) sales@dzone.com
lie and
nt
+ha
n d lere
que
ler
2 Version 1.0
Copyright © 2009 DZone, Inc. All rights Creserved. No part of thiscrepublication
teH ()
may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical,
Con req
uest
photocopying, or otherwise, without prior written permission of nthe
dle publisher. Reference:
s
+ha
ern
1 king
ler by lin .c o
m
and uest one
teH req z
cre () le a w.d
Con uest hand | ww