Tải bản đầy đủ (.pdf) (832 trang)

Beginning Web Programming with HTML, XHTML, and CSS pps

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (16.61 MB, 832 trang )

P1: IML/FFX P2: IML/FFX QC: IML/FFX T1: IML
WY034-FM WY034-Duckett WY034-Duckett-v1.cls December 9, 2004 13:18
ii
Beginning Web Programming
with HTML, XHTML, and CSS
i
P1: IML/FFX P2: IML/FFX QC: IML/FFX T1: IML
WY034-FM WY034-Duckett WY034-Duckett-v1.cls December 9, 2004 13:18
Beginning Web Programming
with HTML, XHTML, and CSS
Jon Duckett
Wiley Publishing, Inc.
iii
P1: IML/FFX P2: IML/FFX QC: IML/FFX T1: IML
WY034-FM WY034-Duckett WY034-Duckett-v1.cls December 9, 2004 13:18
Beginning Web Programming with HTML,
XHTML, and CSS
Copyright
C

2004 by Wiley Publishing, Inc. All rights reserved.
Published simultaneously in Canada
No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form
or by any means, electronic, mechanical, photocopying, recording, scanning, or otherwise, except as
permitted under Section 107 or 108 of the 1976 United States Copyright Act, without either the prior
written permission of the Publisher, or authorization through payment of the appropriate per-copy fee
to the Copyright Clearance Center, Inc., 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax
(978) 646-8700. Requests to the Publisher for permission should be addressed to the Legal Department,
Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317)
572-4355, E-mail:



LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR
MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR
COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WAR-
RANTIES, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONAL
MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE
FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUB-
LISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL
SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT
PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR
SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZA-
TION OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL
SOURCE OF FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUB-
LISHER ENDORSES THE INFORMATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR
RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE THAT INTER-
NET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN
WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ.
For general information on our other products and services please contact our Customer Care
Department within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or
fax (317) 572-4002.
Trademarks: Wiley, Wrox, the Wrox logo, Programmer to Programmer, and related trade dress are
trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United
States and other countries, and may not be used without written permission. All other trademarks are
the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or
vendor mentioned in this book.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print
may not be available in electronic books.
Printed in the United States of America
10987654321

iv
eISBN: 0-7645-7813-8
P1: IML/FFX P2: IML/FFX QC: IML/FFX T1: IML
WY034-FM WY034-Duckett WY034-Duckett-v1.cls December 9, 2004 13:18
About the Author
Jon Duckett published his first Web site in 1996 while studying for a BSc (Hons) in Psychology at Brunel
University, London. Since then he has helped create a wide variety of Web sites and has co-written more
than ten programming-related books on topics from ASP to XML (via many other letters of the alphabet)
covering diverse aspects of Web programming including design, architecture, and coding.
After graduation, Jon worked for Wrox Press first in its Birmingham (UK) offices for three years and then
in Sydney, Australia, for another year. He is now a freelance developer and consultant based in a leafy
suburb of London, working for a range of clients spread across three continents.
When not stuck in front of a computer screen, Jon enjoys listening to music and writing.
v
P1: IML/FFX P2: IML/FFX QC: IML/FFX T1: IML
WY034-FM WY034-Duckett WY034-Duckett-v1.cls December 9, 2004 13:18
Credits
Senior Acquisitions Editor
Jim Minatel
Development Editor
James H. Russell
Production Editor
Eric Newman
Copy Editor
Nancy Rapoport
Editorial Manager
Mary Beth Wakefield
Vice President & Executive Group Publisher
Richard Swadley
Vice President and Executive Publisher

Bob Ipsen
Vice President and Publisher
Joseph B. Wikert
vi
P1: IML/FFX P2: IML/FFX QC: IML/FFX T1: IML
WY034-FM WY034-Duckett WY034-Duckett-v1.cls December 9, 2004 13:18
Contents
Introduction xxiii
Chapter 1: Untangling the Web 1
AWeb of Structured Documents 2
How the Web Works 2
Introducing Web Technologies 4
Introducing HTML 4
Keeping Style Separate from Structure and Semantics 10
Introducing CSS 10
Introducing XHTML 12
Differences Between Writing XHTML and Writing HTML 13
AFew Words About JavaScript 16
Tools for Writing Web Pages 16
Creating Your First Web Page 17
Viewing the Source of Web Pages 21
Summary 22
Exercises 23
Chapter 2: The Structure of a Page 25
Understanding the Basic Document Structure 26
The <html> Element 26
The <head> Element 27
The <title> Element 27
The <body> Element 28
Attribute Groups 29

Core Attributes 29
Internationalization 31
UI Events 33
Basic Text Formatting 33
Whitespace and Flow 34
Creating Headings Using hn Elements 35
Creating Paragraphs Using the <p> Element 38
P1: IML/FFX P2: IML/FFX QC: IML/FFX T1: IML
WY034-FM WY034-Duckett WY034-Duckett-v1.cls December 9, 2004 13:18
Contents
Creating Line Breaks Using the <br /> Element 38
Creating Preformatted Text Using the <pre> Element 39
Presentational Elements 43
The <b> Element 43
The <i> Element 43
The <u> Element (deprecated) 44
The <s> and <strike> Elements (deprecated) 44
The <tt> Element 44
The <sup> Element 44
The <sub> Element 45
The <big> Element 45
The <small> Element 45
The <hr /> Element 46
Phrase Elements 46
The <em> Element Adds Emphasis 47
The <strong> Element Adds Strong Emphasis 47
The <abbr> Element Is for Abbreviations 48
The <acronym> Element Is for Acronym Use 48
The <dfn> Element Is for Special Terms 49
The <blockquote> Element Is for Quoting Text 49

The <q> Element Is for Short Quotations 50
The <cite> Element Is for Citations 51
The <code> Element Is for Code 51
The <kbd> Element Is for Text Typed on a Keyboard 52
The <var> Element Is for Programming Variables 52
The <samp> Element Is for a Program Output 53
The <address> Element Is for Addresses 53
Lists 53
Using the <ul> Element to Create Unordered Lists 54
Ordered Lists 55
Definition Lists 57
Nesting Lists 57
How It Works 60
Editing Text 62
Using <ins> to Indicate New Additions to Text 63
Using <del> to Indicate Deleted Text 63
Using Character Entities for Special Characters 64
Comments 64
The <font> Element (deprecated) 65
Understanding Block and Inline Elements 65
Grouping Elements with <div> and <span> 66
viii
P1: IML/FFX P2: IML/FFX QC: IML/FFX T1: IML
WY034-FM WY034-Duckett WY034-Duckett-v1.cls December 9, 2004 13:18
Contents
Summary 67
Exercises 68
Chapter 3: Links and Navigation 69
Basic Links 69
Linking to Other Documents 70

Linking to E-mail Addresses 72
Understanding Directories and Directory Structures 73
What Are You Linking To? 74
What a URL Is Made Up Of 75
Absolute and Relative URLs 77
The <base> Element 80
Creating Links with the <a> Element 80
Creating a Source Anchor with the href Attribute 81
Creating a Destination Anchor Using the name and id Attributes (linking to a
specific part of a page) 82
Advanced E-mail Links 90
Summary 91
Exercises 91
Chapter 4: Colors, Images, and Objects 93
Adding Color to Your Site 93
Specifying the Color You Want 94
Using Color Names to Specify Colors 97
Hex Codes versus Color Names 97
Choosing Your Colors for the Web 98
The Basics of Color 99
Creating a Color Scheme 100
Contrast 101
Other Things That Affect Color 102
The Web Safe Color Palette 102
Final Words on Color 103
Adding Images to Your Site 103
Types of Image Formats 104
Bitmap Images 104
Vector Images 110
Adding Images Using the <img> Element 111

ix
P1: IML/FFX P2: IML/FFX QC: IML/FFX T1: IML
WY034-FM WY034-Duckett WY034-Duckett-v1.cls December 9, 2004 13:18
Contents
Adding Other Objects with the <object> Element 117
The <object> Element’s Attributes 118
The <param> Element 121
Using Images as Links 122
Image Maps 122
Server-Side Image Maps 124
Client-Side Image Maps 124
Summary 128
Exercises 129
Chapter 5: Tables 131
Introducing Tables 131
Basic Table Elements and Attributes 134
The <table> Element Creates a Table 134
The <tr> Element Contains Table Rows 138
The <td> and <th> Elements Represent Table Cells 140
Advanced Tables 146
Splitting up Tables Using a Head, Body, and Foot 146
Adding a <caption> to a Table 148
Spanning Columns Using the colspan Attribute 149
Spanning Rows Using the rowspan Attribute 149
Grouping Columns Using the <colgroup> Element 151
Columns Sharing Styles Using the <col> Element 152
Accessibility Issues with Tables 153
How Tables Linearize 153
Linearization of Tables Used for Layout 154
Linearization of Tables Used for Data 156

Summary 157
Exercises 157
Chapter 6: Forms 159
Introducing Forms 160
Creating a Form with the <form> Element 161
The action Attribute 161
The method Attribute 162
The id Attribute 162
The name Attribute (deprecated) 162
The onsubmit Attribute 162
The onreset Attribute 163
x
P1: IML/FFX P2: IML/FFX QC: IML/FFX T1: IML
WY034-FM WY034-Duckett WY034-Duckett-v1.cls December 9, 2004 13:18
Contents
The enctype Attribute 163
The accept-charset Attribute 164
The accept Attribute 164
The target Attribute 164
Whitespace and the <form> Element 164
Form Controls 165
Text Inputs 165
Buttons 169
Checkboxes 173
Radio Buttons 175
Select Boxes 177
File Select Boxes 182
Hidden Controls 184
Object Controls 185
Creating Labels for Controls and the <label> Element 188

Structuring Your Forms with <fieldset> and
<legend> Elements 190
Focus 192
Tabbing Order 192
Access Keys 194
Disabled and Read-Only Controls 195
Sending Form Data to the Server 196
HTTP get 196
HTTP post 197
Summary 201
Exercises 201
Chapter 7: Frames 203
When to Use Frames 203
Introducing the Frameset 204
The <frameset> Element 206
The cols Attribute 207
The rows Attribute 209
Browser-Specific Extensions to the <frameset> Element 210
The <frame> Element 211
The src Attribute 212
The name Attribute 213
The frameborder Attribute 213
The marginwidth and marginheight Attributes 213
The noresize Attribute 213
xi
P1: IML/FFX P2: IML/FFX QC: IML/FFX T1: IML
WY034-FM WY034-Duckett WY034-Duckett-v1.cls December 9, 2004 13:18
Contents
The scrolling Attribute 214
The longdesc Attribute 214

The <noframes> Element 214
Creating Links Between Frames 215
Setting a Default Target Frames Using the <base> Element 217
Nested Framesets 217
Floating or Inline Frames with <iframe> 222
The <iframe> Element 223
Summary 226
Exercises 227
Chapter 8: Deprecated and Browser-Specific Markup 229
Why Deprecated Markup Exists 230
Older Pages Break Many Rules 230
Fonts 231
The <font> Element 231
The text Attribute 233
The <basefont> Element 234
The <s> and <strike> Elements 235
The <u> Element 236
The <listing>, <plaintext>, and <xmp> Elements 236
Backgrounds 237
The bgcolor Attribute 238
The background Attribute 239
Formatting 239
The <center> Element 240
The align Attribute 241
The width Attribute 242
The height Attribute 243
The vspace Attribute 244
The hspace Attribute 245
The clear Attribute (on <br /> element) 246
Links 247

Lists 247
The start Attribute 248
The value Attribute 248
The type Attribute 249
The <dir> and <menu> Elements 250
Tables 251
The nowrap Attribute 252
xii
P1: IML/FFX P2: IML/FFX QC: IML/FFX T1: IML
WY034-FM WY034-Duckett WY034-Duckett-v1.cls December 9, 2004 13:18
Contents
Miscellaneous Attributes 252
The border Attribute 252
The compact Attribute 253
The language Attribute 253
The version Attribute 253
The <applet> Element 253
The <embed> Element 254
The <isindex> Element 255
The <nobr> Element 256
IE-Specific Elements 256
IE-Specific Attributes 257
IE-Specific CSS Styles 258
Netscape-Specific Elements and Attributes 260
Netscape-Specific Attributes 261
Summary 263
Exercises 263
Chapter 9: Cascading Style Sheets 265
Introducing CSS 266
A Basic Example 267

Inheritance 270
Where You Can Add CSS Rules 271
The <link> Element 272
The <style> Element 273
Advantages of External CSS Style Sheets 274
CSS Properties 275
Controlling Fonts 276
The font-family Property 278
The font-size Property 279
The font-weight Property 279
The font-style Property 280
The font-variant Property 281
The font-stretch Property 282
The font-size-adjust Property 282
Text Formatting 283
The color Property 283
The text-align Property 284
The vertical-align Property 284
The text-decoration Property 285
The text-indent Property 286
xiii
P1: IML/FFX P2: IML/FFX QC: IML/FFX T1: IML
WY034-FM WY034-Duckett WY034-Duckett-v1.cls December 9, 2004 13:18
Contents
The text-shadow Property 287
The text-transform Property 288
The letter-spacing Property 288
The word-spacing Property 289
The white-space Property 290
The direction Property 290

The unicode-bidi Property 292
Text Pseudo-Classes 292
The first-letter Pseudo-Class 292
The first-line Pseudo-Class 293
Selectors 296
Universal Selector 296
The Type Selector 296
The Class Selector 297
The ID Selector 297
The Child Selector 297
The Descendent Selector 298
The Adjacent Sibling Selector 298
Attribute Selectors 298
Lengths 299
Absolute Units 299
Relative Units 300
Percentages 301
Coming to Grips with the Box Model 301
An Example Illustrating the Box Model 302
The Border Properties 304
The padding Property 308
The margin Property 309
Dimensions 310
Summary 318
Exercises 318
Chapter 10: More Cascading Style Sheets 321
Links 321
Backgrounds 323
The background-color Property 324
The background-image Property 324

The background-repeat Property 326
xiv
P1: IML/FFX P2: IML/FFX QC: IML/FFX T1: IML
WY034-FM WY034-Duckett WY034-Duckett-v1.cls December 9, 2004 13:18
Contents
The background-position Property (for fixing
position of backgrounds) 327
The background-attachment Property (for watermarks) 328
The background Property (the well-supported shorthand) 330
Lists 330
The list-style-type Property 331
The list-style-position Property 331
The list-style-image Property 332
The list-style Property (the shorthand) 333
The marker-offset Property 334
Tables 334
Table-Specific Properties 336
The border-collapse Property 336
The border-spacing Property 338
The caption-side Property 338
The empty-cells Property 339
The table-layout Property 340
Outlines 341
The outline-width Property 342
The outline-style Property 342
The outline-color Property 342
The outline Property (the shorthand) 342
The :focus and :active Pseudo-Classes 342
Generated Content 343
The :before and :after Pseudo-Elements 343

The content Property 344
Miscellaneous Properties 347
The cursor Property 347
The display Property 348
Visibility of Boxes 348
Additional Rules 349
The @import Rule: Modularized Style Sheets 349
The @charset Rule 350
!important 351
Positioning with CSS 351
Normal Flow 351
The position Property 352
Box Offset Properties 353
Relative Positioning 353
Absolute Positioning 354
Fixed Positioning 356
xv
P1: IML/FFX P2: IML/FFX QC: IML/FFX T1: IML
WY034-FM WY034-Duckett WY034-Duckett-v1.cls December 9, 2004 13:18
Contents
The z-index Property 356
Floating Using the float Property 358
The clear Property 359
Overflow 361
Summary 367
Exercises 368
Chapter 11: Page Layout 371
Understanding the Site 371
Understanding a Site’s Aims 372
Who You Expect to Visit 373

New Content 373
Defining Your Site’s Content 374
Grouping and Categorization 375
Creating a Site Map 375
Identifying Key Elements for Every Page 377
Page Size (and Screen Resolution) 377
Fixed-Width versus Liquid Designs 379
Designing Pages 388
Sketching the Placement of Elements 388
Introducing the Style 391
Navigation 394
Home Pages 397
Content Pages 397
Structuring Pages 398
Single-Column Layouts 400
Two-Column Layouts 403
Three-Column Layouts 405
Sacrificial Columns 408
Fixing a Minimum Width of a Column 408
Nesting Tables Inside Tables 409
Rethinking Design for CSS 412
Summary 416
Exercises 418
Chapter 12: Design Issues 419
Text 420
Whitespace Helps Make More Attractive Pages 420
Carefully Aligned Text Is More Readable 422
xvi
P1: IML/FFX P2: IML/FFX QC: IML/FFX T1: IML
WY034-FM WY034-Duckett WY034-Duckett-v1.cls December 9, 2004 13:18

Contents
Wide Columns of Text Are Harder to Read 423
Background Images Can Make Text Hard to Read 424
Choose Fonts Carefully 424
Fixed Size Fonts Are Affected by Screen Resolution 426
Navigation 426
Menus 426
Links 432
Site Search Features 432
Tables 435
Shading Multiple Rows of a Table 435
Creating a Custom Frame with Tables 436
Creating a Drop Shadow with a Table 438
Forms 440
Before Designing the Form 440
Designing the Form 442
Summary 463
Exercises 463
Chapter 13: Modularized XHTML and Serving Multiple Devices 465
Introducing Modularized XHTML 466
Where We Are Today 466
Modularizing XHTML 467
XHTML 1.1 470
Looking at XHTML 1.1’s Modules 471
The Differences Between XHTML 1.0 and XHTML 1.1 474
XHTML Basic 475
What Is XHTML Basic? 475
What XHTML Basic Includes and Leaves Out 476
Understanding XML Namespaces 477
Hybrid Document Types 479

XHTML on Mobile Phones 482
The Background 483
Mobile Access Today 484
Creating Sites for Different Platforms 484
Working with (not Against) the Constraints of a Device 485
Why Use XHTML if Content or Sections of Sites
Are Different? 486
Database-Driven Web Sites 486
Transforming Pages Using XSLT 492
xvii
P1: IML/FFX P2: IML/FFX QC: IML/FFX T1: IML
WY034-FM WY034-Duckett WY034-Duckett-v1.cls December 9, 2004 13:18
Contents
Complementary Services for Different Devices 493
More to Come. . . 494
Summary 494
Exercises 495
Chapter 14: Learning JavaScript 499
What Is Programming About? 500
How to Add a Script to Your Pages 501
Comments in JavaScript 503
The <noscript> Element 504
The Document Object Model 505
Introducing the Document Object Model 505
Objects, Methods, and Properties 508
The Forms Collection 510
Form Elements 511
Images Collection 514
Different Types of Objects 517
Starting to Program with JavaScript 517

Variables 518
Assigning a Value to a Variable 519
Lifetime of a Variable 519
Operators 520
Arithmetic Operators 520
Assignment Operators 521
Comparison Operators 521
Logical or Boolean Operators 522
String Operator 522
Functions 523
How to Define a Function 523
How to Call a Function 523
The Return Statement 524
Conditional Statements 524
if Statements 525
if. . . else Statements 525
A switch Statement 526
Conditional (or Ternary) Operator 527
Looping 528
while 528
do. . . while 529
xviii
P1: IML/FFX P2: IML/FFX QC: IML/FFX T1: IML
WY034-FM WY034-Duckett WY034-Duckett-v1.cls December 9, 2004 13:18
Contents
for 529
Infinite Loops and the break Statement 530
Events 530
Built-in Objects 532
String 532

Date 536
Math 539
Array 541
Window 542
Writing JavaScript 544
AWord About Data Types 545
Keywords 546
Summary 546
Exercises 547
Chapter 15: Creating a JavaScript Library 549
Practical Tips for Writing Scripts 549
Has Someone Already Written This Script? 549
Reusable Functions 550
Using External JavaScript Files 551
Place Scripts in a Scripts Folder 551
Form Validation 551
When to Validate 551
How to Validate 552
Form Enhancements 566
Focus on First Form Item 566
Auto-Tabbing Between Fields 567
Disabling a Text Input 568
Case Conversion 569
Trimming Spaces from Beginning and End of Fields 570
Selecting All of the Content of a Text Area 571
Check and Uncheck All Checkboxes 572
How It Works 576
Breadcrumb Trails 578
Image Rollovers 582
Random Script Generator 585

Pop-Up Windows 585
When Not to Use JavaScript 587
Drop-Down Navigation Menus 587
xix
P1: IML/FFX P2: IML/FFX QC: IML/FFX T1: IML
WY034-FM WY034-Duckett WY034-Duckett-v1.cls December 9, 2004 13:18
Contents
Hiding Your E-mail Address 588
Quick Jump Select Boxes 588
Anything the User Requires from Your Site 588
Summary 588
Exercises 589
Chapter 16: Taking Your Site Live 591
Meta Tags 592
name and content Attributes 592
Using name with a Value of robots 594
http-equiv and content 594
scheme 598
Testing Your Site 598
The Importance of Directory Structure and Relative URLs 599
Validating HTML, XHTML, and CSS 599
Link Checking 600
Checking Different Screen Resolutions and Color Depths 604
Accessibility Checkers 604
Development Server or Live Server 606
Checking in Different Versions of Browsers 606
Pilot Testing 607
Proofreading 608
Taking the Leap to Live 608
Getting a Domain Name 608

Hosting 609
Search Engine Strategies 614
Other Web Marketing Possibilities 616
Statistical Analysis 617
Version Control 619
What Next? 620
Blogs 621
Discussion Boards or Forums 621
Adding a Search Utility 622
Introducing Other Technologies 622
Server-Side Web Programming: ASP, JSP, and PHP 622
Choosing a Server-Side Language 623
Content Management 624
Flash 628
Learning Graphics Packages 628
Summary 629
xx
P1: IML/FFX P2: IML/FFX QC: IML/FFX T1: IML
WY034-FM WY034-Duckett WY034-Duckett-v1.cls December 9, 2004 13:18
Contents
Appendix A: Answers to Exercises 631
Appendix B: XHTML Element Reference 663
Appendix C: CSS Properties 701
Appendix D: Color Names and Values 729
Appendix E: Character Encodings 735
Appendix F: Special Characters 739
Appendix G: Language Codes 751
Appendix H: MIME Media Types 757
Index 765
xxi

P1: IML/FFX P2: IML/FFX QC: IML/FFX T1: IML
WY034-FM WY034-Duckett WY034-Duckett-v1.cls December 9, 2004 13:18
xxii
P1: IML/FFX P2: IML/FFX QC: IML/FFX T1: IML
WY034-FM WY034-Duckett WY034-Duckett-v1.cls December 9, 2004 13:18
Introduction
There are a lot of books about designing and building Web pages, so thank you for picking up this one.
Why do I think it is different? Well, the Web has been around for quite a few years now, and during its life
several technologies have been introduced to help you create Web pages, some of which have lasted,
others of which have disappeared. Indeed, even enduring technologies such as HTML have had features
added and removed over the years. Many books that teach you to write Web pages are revisions of earlier
versions of the same book and therefore still take the same approach as the previous edition did. This
book, however, is completely new, written from scratch, and its purpose is to teach you how to create
Web pages for the Web as it is today and will be for the next few years. Once you have worked through
this book, it should continue to serve as a helpful reference text you can keep nearby and dip into when
you need to.
About the Book
At the time of this writing, Internet Explorer version 6 and Netscape version 7 are the main Web
browsers, and each of the previous versions of these browsers had added new features as the Web
developed (and sometimes old features were removed). As all this change might suggest, there is more
than one way to build a Web site. For example, if you want to have a heading for a page displayed in a
bold, black, Arial typeface, you can achieve this in several ways. However, you can also consider this a
very good time to come to the Web, as many of the technologies used to create Web pages are maturing,
and favored methods for creating Web sites, or “best practices,” are emerging.
Writing Web pages today thus requires a balance. On the one hand you want to use the latest and best
methods, while on the other hand you have to remember that not everyone who visits your Web site has
the latest browser software. So you need to be able to write pages that take advantage of the features of
the latest browsers while at the same time ensuring your sites can be viewed in older browsers. (Indeed, if
you want to make a living from working on Web pages, you will need to be aware of some of the older
ways of doing things.) In this book, I teach you the best practices that you should be learning, and, where

necessary, I expose the older techniques that help you achieve the results you want.
Over the past few years there have also been innovations and changes in the way people access the
Internet. The Web is no longer just viewed on desktop computers; Web sites are becoming available on
devices with small screens, such as mobile phones and PDAs (personal digital assistants), and some
devices such as televisions have lower resolutions than computer monitors. There are even stories in the
newspapers about how we will all soon have refrigerators and other appliances that will allow us to
browse the Web. So, while most of the examples in this book are written for a computer, I will teach you
to code your Web pages so that you can make them available to other devices without rewriting your
whole site. Learning to code for the emerging generation of applications will make your Web sites and
your skills last much longer.
Another area where the Web has changed from a few years back is the increased emphasis on usability
and accessibility. Usability refers to making the site easy for users to get around (or navigate) and achieve
what they came to your site for, whereas accessibility addresses making a site available to as many users as
P1: IML/FFX P2: IML/FFX QC: IML/FFX T1: IML
WY034-FM WY034-Duckett WY034-Duckett-v1.cls December 9, 2004 13:18
Introduction
possible, in particular people with disabilities (who may have impaired vision or difficulty using a
mouse). Many governments around the world will not issue a contract to build Web sites for them unless
the site will meet strict accessibility standards. A little careful thought before you build your Web site
means that people with vision impairments can either view your site with larger text or have it read to
them by a screen reader. There are books dedicated to the topics of usability and accessibility that are
aimed at Web developers who need to learn how to make their code more accessible and usable, but my
aim is to teach you to code with these principles in mind from the start.
By the end of this book, you will be writing Web pages that not only use the latest technologies, but also
are still viewable by older browsers. Pages that look great can still be accessed by those with visual and
physical impairments—pages that not only address the needs of today’s audiences but can also work on
emerging technologies—and the skills you learn should be relevant for longer.
Who This Book Is For
This book is written for anyone who wants to learn how to create Web pages, and for people who might
have dabbled in writing Web pages (perhaps using some kind of Web page authoring tool) but want to

really understand the languages of the Web to create better pages.
More experienced Web developers can also benefit from this book because it teaches some of the latest
technologies, such as XHTML, and encourages you to embrace Web standards that not only meet the
needs of the new devices that access the Web, but also help make your sites available to more visitors.
Youdonot need any previous programming experience to work with this book—even though these big
redWrox books are published under the trademark Programmer to Programmer (because the books are
written by programmers for programmers). This is one of the first steps on the programming ladder.
Whether you are just a hobbyist or want to make a career of Web programming, this book will teach you
the basics of programming for the Web. Sure, the term “programmer” might be associated with geeks,
but as you will see by the end of the book, even if you would prefer to be known as a Web designer, you
need to know how to code to write great Web sites.
What This Book Covers
By the end of this book, you will be able to create professional looking, and well-coded Web pages.
Not only will you learn the code that makes up markup languages such as HTML, but you will also see
how to apply this code so you can create sophisticated layouts for your pages, positioning text and
images where you want and getting the colors and fonts you want. Along the way, you will see how to
make your pages easy to use and available to the biggest audience possible. You will also learn practical
techniques such as how to put your Web site available on the Internet and how to get search engines to
recognize your site.
The main technologies covered in this book are HTML, XHTML, and CSS. XHTML is not actually a
completely different language than HTML; it is more like the latest version of it. What would have been
HTML 5 was named XHTML, rather like how Microsoft called what would have been Windows 2001
Windows XP. XHTML stands for eXtensible Hypertext Markup Language; it describes the structure of
Web pages such as the headings, paragraphs of text, tables, bulleted lists, and so on. CSS is then used to
apply styles the documents, to change things such as colors, typefaces, sizes of text, and so on. Once you
xxiv
P1: IML/FFX P2: IML/FFX QC: IML/FFX T1: IML
WY034-FM WY034-Duckett WY034-Duckett-v1.cls December 9, 2004 13:18
Introduction
have learned the basics of these languages you will learn some more practical aspects of applying them.

You will also learn the basics of JavaScript, enough to work on some examples that add interactivity to
you pages and allow you to work with basic scripts. Along the way I introduce and point you to other
technologies you might want to learn in the future.
The code I will encourage you to write is based on what are known as Web standards; HTML, XHTML,
and CSS are all created and maintained by the World Wide Web Consortium, or W3C (http://www.w3
.org/), an organization dedicated to creating specifications for the Web. You will also learn about some
features that are not standards, but it is helpful to know some of these in case you come across such
markup and need to know what it does (where these are introduced I make it clear that they are not part
of the standard).
What You Need to Use This Book
All you need to work through this book is a computer with a Web browser (preferably Netscape 6 or
higher, or Internet Explorer 6 or higher), and a simple text editor such as Notepad on Windows or
SimpleText on Mac.
If you have a Web page editor program, such as Macromedia Dreamweaver or Microsoft FrontPage, you
are welcome to use it, but I will not be teaching you how to use these programs. Each program is different
and entire books could be and have been written on the individual programs. Even if you were to use one
of these tools, you can write much better sites when you really understand the code such programs
generate. Like many of the other books on the shelves, these programs were created years ago and do not
address the best way to write pages today. They get jobs done, but not necessarily in the best way
possible, so you will often want to edit the code they create.
How This Book Is Organized
The first chapter of this book gives you the big picture of creating pages for the Web. It explains how all
the technologies you will be learning in this book fit together. In this very first chapter you will also create
your first Web page and learn how the main task in creating a Web site is marking up the text you want to
appear on your site using things called elements and attributes.
The next six chapters of the book describe the different elements and attributes that make up HTML and
XHTML and how you can use them to write Web pages. The chapters are organized into task-related
areas, such as structuring a document into headings and paragraphs, creating links between pages,
adding color and images, displaying tables, and so on. With each task or topic that is introduced you will
see an example first to give you an idea of what is possible; then you can look at the elements and

attributes used in detail.
These task-focused chapters are followed by one on deprecated markup, which is markup that is no longer
part of XHTML, and browser-specific markup, which was introduced by the main browser vendors but
not used in the W3C HTML and XHTML recommendations. While you should not rely on this markup
for writing your pages, you are likely to come across it when working with older Web pages.
At the end of each are exercises that are designed to get you working with some of the concepts you
learned about in each chapter. Don’t worry if you have to go back and review the content of the chapter in
order to complete the exercises; this book has been created with the intention that it should be a helpful
xxv

×