XHTML Basics What is XHTML n n XHTML
XHTML Basics
What is XHTML? n n XHTML is newer than, but built upon, the original HTML (Hyper Text Markup Language) platform. XHTML has stricter rules and does not allow some elements formerly used in HTML. One benefit of using XHTML is that it helps make web pages look identical in different browsers, such as Internet Explorer, Firefox, Safari, etc. XHTML is used to define and organize the page content but not to format or style it.
The history of HTML: 1991 HTML first published 1995 HTML 2. 0 1997 HTML 3. 2 1999 HTML 4. 01 2000 XHTML 1. 0 2002 2009 2012 XHTML 2. 0 HTML 5 After HTML 4. 01 was released, focus shifted to XHTML and its stricter standards. XHTML 1. 0 is what we will learn in this course. XHTML 2. 0 had even stricter standards than 1. 0, but it fell out of favor gradually and was abandoned completely in 2009. HTML 5 added powerful new features for creating web pages. It is still a work in progress but will eventually replace XHTML as the standard platform to build websites.
A basic XHTML document: <!DOCTYPE html PUBLIC "-//W 3 C//DTD XHTML 1. 0 Transitional//EN" "http: //www. w 3. org/TR/xhtml 1/DTD/xhtml 1 -transitional. dtd"> <html xmlns="http: //www. w 3. org/1999/xhtml" xml: lang="en"> <head> <title>My First Web Page</title> </head> <body> <p>Hello World</p> </body> </html>
DOCTYPE must be specified on the first line: <!DOCTYPE html PUBLIC "-//W 3 C//DTD XHTML 1. 0 Transitional//EN" "http: //www. w 3. org/TR/xhtml 1/DTD/xhtml 1 -transitional. dtd"> The DOCTYPE tells the web browser which language is being used for the set of instructions that follow. In this class, we will be using XHTML Transitional, which allows us more flexibility than XHTML Strict.
In XHTML, all elements must be in lowercase (the DOCTYPE line is not an element. ) <html xmlns="http: //www. w 3. org/1999/xhtml" xml: lang="en"> <head> <title>My First Web Page</title> </head> <body> <p>Hello World</p> </body> </html>
Each element must have a beginning and an end: <html xmlns="http: //www. w 3. org/1999/xhtml" xml: lang="en"> <head> <title>My First Web Page</title> </head> <body> <p>Hello World</p> </body> </html>
Elements must be properly nested: <html xmlns="http: //www. w 3. org/1999/xhtml" xml: lang="en"> <head> <title>My First Web Page</title> </head> <body> <p>Hello World</p> </body> </html>
What is wrong with this? <h 1>My Favorite Things</h 1> <ul> <li>Brown <p> paper packages</li> Tied up with strings</p> </ul>
What is wrong with this? <h 1>My Favorite Things</h 1> <ul> <li>Brown <p> paper packages</li> Tied up with strings</p> </ul> The tags are overlapped.
White space doesn’t matter. The browser will ignore blank lines and multiple spaces: <ul> <li>First Item</li><li>Second Item</li> </ul> is the same as: <ul> <li>First Item</li> <li>Second Item</li> </ul> We can take advantage of this fact by putting blank lines and indents in our code to make it easier to organize and read.
Summary of XHTML Basics: DOCTYPE must be specified first. n All elements must be in lowercase. n Each element must have a beginning and an end. n Elements must be properly nested. n White space doesn’t matter. n
- Slides: 12