7 ways to write "Better" HTML
+7 ways it will benefit your online business
Ca Phun Ung
Introduction
Some definitions:
- "Better" meaning semantically rich and standards compliant.
- HTML 4.x and XHTML1.x
Introduction
- HTML is an age old topic
- Hong Kong needs more awareness of Web Standards
- Presentation purpose - Spark interest
- Please feel free to butt in!
7 Ways to write "Better" HTML
- Use a DOCTYPE declaration
- Don't Abuse the Good!
- Use the Right Tag for the Right Job
- Avoid Bed and BReakfast markup
- Headings are important
- Don't forget ALT text!
- Use CSS for presentation
1. Use a DOCTYPE declaration
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- Strict DTD - standards mode
1. Use a DOCTYPE declaration
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- Transitional DTD - almost-standards mode
1. Use a DOCTYPE declaration
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
- Frameset DTD - when using frames to layout a document
1. Use a DOCTYPE declaration
- DOCTYPEs let user agents & validators know the DTD of the document
- DOCTYPE switching - "quirks mode" and "standards mode"
- Infamous Box model issue:
- W3C model - Box width = the containing content
- IE 5.x/IE6 quirks mode - Box width = borders + padding + content
- For more info, see:
2. Don't Abuse the Good!
- HTML is simple
- Easy enough to learn by example
- Therefore prone to exploitation
- Most abused are TABLEs and BLOCKQUOTEs
2. Don't Abuse the Good—TABLEs
- Throw away your TABLEs
- It adds unnecessary clutter
- It suffocates your content
- For more, see:
2. Don't Abuse the Good—TABLEs
- But keep the "data tables"
|
Guthrie |
MacFarlane |
| 1.30pm |
Brett, John, David |
Roger |
| 2.15pm |
Dean |
Lisa, Peter |
2. Don't Abuse the Good—BLOCKQUOTEs
- <blockquote> != indentation
- <blockquote> = a block of quotes
- <blockquote> always starts with <p>
- Example…
2. Don't Abuse the Good—BLOCKQUOTEs
<p> Eric Meyer wrote:</p>
<p>
What's so interesting to me is that the guys who decided
to focus on the positive went out and did something;
those who want to mix in the negative seem to have
nothing to offer except complaints.
</p>
<p>An excellent contrast between those who want to
build new things and those who want to tear them down.
</p>
2. Don't Abuse the Good—BLOCKQUOTEs
<p><cite>Eric Meyer</cite> wrote:</p>
<blockquote>
<p>
What's so interesting to me is that the guys who decided
to focus on the positive went out and did something;
those who want to mix in the negative seem to have
nothing to offer except complaints.
</p>
</blockquote>
<p>An excellent contrast between those who want to
build new things and those who want to tear them down.
</p>
2. Don't Abuse the Good—BLOCKQUOTEs
<p><cite>Eric Meyer</cite> wrote:</p>
<blockquote cite="http://meyerweb.../social-protocols/">
<p>
What's so interesting to me is that the guys who decided
to focus on the positive went out and did something;
those who want to mix in the negative seem to have
nothing to offer except complaints.
</p>
</blockquote>
<p>An excellent contrast between those who want to
build new things and those who want to tear them down.
</p>
2. Don't Abuse the Good—BLOCKQUOTEs
<p><cite>Eric Meyer</cite> wrote:</p>
<blockquote cite="http://meyerweb.../social-protocols/">
<p>
What's so interesting to me is that the guys who decided
to focus on the positive went out and did something;
those who want to mix in the negative seem to have
nothing to offer except complaints.
</p>
</blockquote>
<p>An excellent contrast between those who want to
build new things and those who want to tear them down.
</p>
3. Use the Right Tag for the Right Job
- Avoid <b> <br/> <i> <sub> <sup>
- <h1> != big and bold
- <em> != make this italic
- <blockquote> != indent this
3. Use the Right Tag for the Right Job
- <p>This is a Paragraph</p>
- <h1>Most</h1> to <h6>Least</h6> important headings
- <em>I'm angry!</em>
- <strong>I'm very angry!</strong>
- <em><strong>I'm super angry!</strong></em>
- <ul> vs. <ol> vs. <dl>
4. Avoid Bed and BReakfast markup
4. Avoid Bed and BReakfast markup
<b>cool stuff recently discovered</b>
<br>
so and so pointed me to this site where they've
introduced this amazing new product.
when can i get one?
<br>
also cool is this new service offered by example.net.
this will save me so much time in my work.
<br>
4. Avoid Bed and BReakfast markup
<div class="entry">
<h2>cool stuff discovered</h2>
<p>
so and so pointed me to this site where they've
introduced this amazing new product.
when can i get one?
</p>
<p>
also cool is this new service offered by example.net.
this will save me so much time in my work.
</p>
</div>
5. Headings are important
- There are six levels
- Where to start your <h1>?
- Many <h1>s are allowed
- Do not skip levels
- User the Web developer toolbar:
- Information > View Document Outline
5. Headings are important
- Headings are good for accessibility
- Headings are good for SEO
- Headings are much better than <div>s or <span>s
6. Don't forget ALT text!
- Bad:
<img src="car_photo.jpg">
- Acceptable:
<img src="car_photo.jpg" alt="">
- Good:
<img src="car_photo.jpg" alt="my dream car">
6. Don't forget ALT text!
- It's a basic requirement for WAI level 1 compliance
- Good for text based browsers and screen readers
- Additionally, use the title attribute to help users predict where they are going
- For more info, see:
7. Use CSS for presentation
- CSS complements HTML
- Best way to learn is by example
- CSS Frameworks:
7 ways it will benefit your online business
- Your pages will load faster
- Lower your hosting costs
- Lower the cost of a redesign
- Helps to maintain visual consistency
- Better search engine results
- More accessible to all viewers and user agents
- It's a winner!