XHTML Tutorial: Author: Dwight Vantuyl Created: September 15, 2008
XHTML Tutorial: Author: Dwight Vantuyl Created: September 15, 2008
XML
HTML
XHTML
Content vs. Presentation
• HTML (content)
– Historically was used for rendering content and
presentation
– Now, push is to use only for describing content – e.g.
Header, paragraph, list, image, etc.
– Still backwards compatible and can be used for
presentation
• CSS (presentation)
– Introduced after the web started getting really ‘fancy.’
– Now, we use a separate CSS file for the
presentation – e.g. Layout, color, font, position, size,
etc.
W3C
• The World Wide Web Consortium (W3C)
is the main international standards
organization for the World Wide Web
(abbreviated WWW or W3).
• Learn more about HTML and XHTML at:
http://www.w3schools.com/
• Also Check Out:
HTML For the World Wide Web by Elizabeth Castro
Elements and Attributes
<element_name attribute_name="attribute_value">
Element Content
</element_name>
• Elements (aka tags): specify the type of content
– how the content will be used in an XML
document. XHTML defines its own set of valid
element_names (e.g. head, body, h1).
• Attributes: give special properties to each
element. Again, XHTML defines its own set of
valid attribute_names (e.g. class, style, id).
Important XHTML Rules
• Elements must be properly nested
– Wrong: <ul><li>blah blah</ul></li>
– Right: <ul><li>blah blah</li></ul>
• the DOCTYPE
• the Head
• the Body
DOCTYPE
(example01.xhtml)
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<h1>Header 1</h1>
<h2>Header 2</h2>
<h3>Header 3</h3>
<h4>Header 4</h4>
<h5>Header 5</h5>
<h6>Header 6</h6>
Header Elements <h1>…<h6>
(example04.xhtml -- rendered)
Horizontal Rule <hr/>
• Render’s a horizontal line across the width
of the containing element.
• Empty – doesn’t contain any content so it
is closed within the tag.
• !!! Always close your tags !!!
Horizontal Rule <hr/>
(example05.xhtml)
<hr/>
Horizontal Rule <hr/>
(example05.xhtml -- rendered)
Paragraph <p>
• Renders a block of text that wraps its
content within the containing paragraph
element.
• XHTML automatically adds an extra blank
line before and after a paragraph.
Paragraph <p>
(example06.xhtml)
...
<p>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Vestibulum posuere mi eget odio. Donec at libero sit amet nunc
venenatis fringilla. Sed a magna. Phasellus nec eros. Nulla
gravida imperdiet elit. Aliquam tempor, diam quis pharetra
rutrum, purus ipsum porta lectus, eu sollicitudin turpis ante ut
felis. Donec sollicitudin posuere augue. Proin dui quam, blandit
non, sagittis tempus, feugiat sed, lacus. Duis in massa quis nibh
iaculis dignissim. Nam non quam. Praesent viverra suscipit justo.
Quisque mauris mi, adipiscing et, viverra vel, molestie sed, justo.
Maecenas vel augue sit amet eros egestas tempor. Maecenas
sed urna quis tortor molestie venenatis. Vestibulum id sapien.
Integer tempus magna vel justo.
</p>
Paragraph <p>
(example06.xhtml -- rendered)
Line Break <br/>
• Even though you may have added line breaks
within your content by using the [Enter] key, they
will not render -- you must use the <br/>
element.
• Empty – doesn’t contain any content so it is
closed within the tag.
• Don’t go overboard!! Using more than one or
two line breaks at a time is considered bad style.
Use CSS for positioning elements on the page
instead.
Line Break <br/>
(example07.xhtml)
...
<p>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vestibulum
posuere mi eget odio. Donec at libero sit amet nunc venenatis fringilla.
Sed a magna. Phasellus nec eros. Nulla gravida imperdiet elit. Aliquam
tempor, diam quis pharetra rutrum, purus ipsum porta lectus, eu
sollicitudin turpis ante ut felis. Donec sollicitudin posuere augue.
<br/><br/>
Proin dui quam, blandit non, sagittis tempus, feugiat sed, lacus. Duis in
massa quis nibh iaculis dignissim. Nam non quam. Praesent viverra
suscipit justo. Quisque mauris mi, adipiscing et, viverra vel, molestie
sed, justo.
<br/></br>
Maecenas vel augue sit amet eros egestas tempor. Maecenas sed
urna quis tortor molestie venenatis. Vestibulum id sapien. Integer
tempus magna vel justo.
</p>
Line Break <br/>
(example07.xhtml -- rendered)
Lists <ul> & <li>
• Used for rendering a bulleted list of items
(bullet can be changed to any char or no
char at all using CSS).
• <li> item </li> elements are enclosed in
<ul> </ul> tags.
• Must NOT put any content inside <ul>
elements unless inside of <li> element.
• <li> elements can NOT be used alone
without being nested inside <ul> tags.
Lists <ul> & <li>
(example08.xhtml)
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
</ul>
Lists <ul> & <li>
(example08.xhtml -- rendered)
Anchor & Hyperlink <a href=“ ”>
• Directs browser to an HTML page, an
image, a sound file, a movie, etc.
• Attributes:
– href: link destination to a URL, #id of an
element, or image file name.
– target=‘_blank’: use if opening in new window
• Inline element (not block)
Anchor & Hyperlink <a href=“ ”>
(example09.xhtml)
<hr/>
Image <img />
(example10.xhtml -- rendered)
Tables <table><tr><td>
• DON’T USE TABLES – unless absolutely necessary.
• Why? Its better to separate content (HTML) from
presentation (CSS).
– Easier to maintain
– Easier to modify
– Cleaner code
• Most everything tables are used for can and should be
done with CSS.
• Why learn tables? Because linguistlist.org, like much of
the web, was built long before CSS came around. Tables
were used to provide layout to a page. So we need to
understand tables in order to maintain old pages. Even
now, people still use tables who don’t understand CSS.
• Don’t create tables! Learn CSS instead!
Tables <table><tr><td> cont.
• <table> : encloses the whole table
• <tr> : defines a table row
• <td> : defines a column in a table row.
This is where your content belongs.
• !!! Don’t put content in anything but the
<td> !!!
Tables <table><tr><td> cont.
• Table Structure:
<table>
<tr>
<td>
row1 col1
</td>
<td>
row1 col2 row1 col1 row1 col2
</td>
</tr>
<tr>
<td>
row2 col1 row2 col1 row2 col2
</td>
<td>
row2 col2
</td>
</tr>
</table>
Tables <table><tr><td>
(example11.xhtml –rendered)
CSS Preview
• Adding tables in order to layout content
makes html unwieldy and difficult to
understand.
• Better solution is to NOT use tables and
position all elements with a separate CSS
file.
• CSS is used for the “presentation” part of
a web page – e.g. color, size, position,
layout, font, etc.
CSS Preview cont.
• CSS properties can be attached to most
elements with two important attributes:
– id: the specific identity of an element – like social
security number
– class: a grouping name to add a style to many
elements.
• We’ll also learn two new elements that help CSS
out but do not render anything on their own:
– div
– span