Beginner Web Standards FAQs

Table of Contents

  1. Doctypes
  2. Inline vs. block elements
  3. Relative vs. absolute positioning.
  4. The box model
  5. Floats and Clears
  6. Top 11 Accessibility Tips
  7. Top 10 SEO Tips
Different kinds of doctypes. When would you want to use one over another?

The DOCTYPE declaration should always be the first line in an XHTML document.

Frameset
If you are using frames, use this.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
Transitional
The XHTML transitional DTD is based on the HTML4.0 transitional DTD, this will support most deprecated elements in order to compensate for older browsers.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Strict
This doctype requires all tags be closed, all markup be seperated from visual display, and forbids the use of deprecated elements and frames.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

An XHTML DTD describes in precise, computer-readable language, the allowed syntax and grammar of XHTML markup.

Added Info - Identifying your language

Like the DOCTYPE, you should identify your language on every page of your web site. <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

Inline vs. block elements

Quoted excerpts from: http://www.autisticcuckoo.net/archive.php?id=2005/01/11/block-vs-inline-1

Block-level elements are rendered with an implicit line break before and after, while inline-level elements are rendered where they occur in the text flow.

Ignoring CSS (The display property, as the name implies, only controls the presentation of an element, not what it is.), a block level element CANNOT be contained by an inline element.

For example:
Valid - <div><a href="#"></a></div>
Invalid - <span><p></p></span>

The div is block level and contains a, which is inline, therefore it will validate.

The span is inline and contains p, which is block level, therefore it will not validate.

The exception is the OBJECT element type, which may, in fact, also contain block-level elements.

Some block-level elements are only allowed to contain other block-level elements. One example is FORM. In strict document types, the BODY may only contain block-level elements. All copy text must thus be marked up with paragraphs or other block-level element types.

For a floating or absolutely positioned element, the display property is generally ignored

An inline display will ignore vertical margins along with width and height.

Relative vs. absolute positioning

From: http://www.w3.org/TR/REC-CSS2/visuren.html#choose-position

Relative
The box's position is calculated according to the normal flow (this is called the position in normal flow). Then the box is offset relative to its normal position. When box A is relatively positioned, the position of the following box B is calculated as though A were not offset.
Absolute
The box's position (and possibly size) is specified with the 'left', 'right', 'top', and 'bottom' properties. These properties specify offsets with respect to the box's containing block. Absolutely positioned boxes are taken out of the normal flow. This means they have no impact on the layout of later siblings. Also, though absolutely positioned boxes have margins, they do not collapse with any other margins.
The box model. Which browsers have troubles interpreting it correctly? how to fix it?

Source: http://www.autisticcuckoo.net/archive.php?id=2005/01/12/block-vs-inline-2

The CSS 2.1 specification says that the width (height) of a block box is computed as the sum of the width (height) of the content area and the widths (heights) of its horizontal (vertical) padding and borders. Margins lie outside the box and are thus unaffected by properties for e.g. background colour.

Consider an element with the following CSS rules:

div#foo {
width:200px;
height:100px;
padding:20px;
border:10px solid #000;
}

The width of the generated block box is 200 + 20 + 20 + 10 + 10 = 260 pixels, while the height is 100 + 20 + 20 + 10 + 10 = 160 pixels. Note that both the left and right (or top and bottom) values must be included for padding and border widths.

Padding and border widths are thus added to the specified content area size. Microsoft got this wrong in older versions of Internet Explorer by using the specified width and height values as the outer dimensions of the block box, and subtracting the padding and border widths to compute the size of the content area.

To overcome this inconsitency, use the simplified box model hack.

width: 253px; // read by all browsers, used for IE5.x
w\idth: 200px; // read by all browsers, but ignored by IE5.x

The result is that the browsers the correctly implements the box model with have the correct width(100px), while IE5.x and lower with only see the 140px width. http://css-discuss.incutio.com/?page=BoxModelHack

How do floats and clears work? How can you self-clear a div?

From: http://css.maxdesign.com.au/floatutorial/clear.htm

Elements following a floated element will wrap around the floated element. If you do not want this to occur, you can apply the "clear" property to these following elements. The four options are clear: left, clear: right, clear: both or clear: none.

clear: left - The element is moved below the bottom outer edge of any left-floating boxes that resulted from elements earlier in the source document.

clear: right - The element is moved below the bottom outer edge of any right-floating boxes that resulted from elements earlier in the source document.

clear: both - The element is moved below all floating boxes of earlier elements in the source document.

Auto-clearing floats: http://www.positioniseverything.net/easyclearing.html

.clearfix:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
* html .clearfix {height: 1%;}


Floats:

According to the W3C (http://www.w3.org/TR/CSS21/visuren.html#floats):

A float is a box that is shifted to the left or right on the current line. The most interesting characteristic of a float (or "floated" or "floating" box) is that content may flow along its side (or be prohibited from doing so by the 'clear' property).

Top 11 ways to make a page more accessible
  1. Using relative font sizes - http://diveintoaccessibility.org/day_26_using_relative_font_sizes.html
  2. Using real headers - http://diveintoaccessibility.org/day_27_using_real_headers.html
  3. Labeling form elements - http://diveintoaccessibility.org/day_28_labeling_form_elements.html
  4. Presenting your main content first - http://diveintoaccessibility.org/day_10_presenting_your_main_content_first.html
  5. Skipping over navigation links - http://diveintoaccessibility.org/day_11_skipping_over_navigation_links.html
  6. Using real links (not javascript based) - http://diveintoaccessibility.org/day_13_using_real_links.html
  7. Constructing meaningful page titles - http://diveintoaccessibility.org/day_8_constructing_meaningful_page_titles.html
  8. Providing text equivalents for images - http://diveintoaccessibility.org/day_23_providing_text_equivalents_for_images.html
  9. Using color safely - http://diveintoaccessibility.org/day_12_using_color_safely.html
  10. Adding titles to links - http://diveintoaccessibility.org/day_14_adding_titles_to_links.html
  11. Using real lists (or faking them properly) - http://diveintoaccessibility.org/day_22_using_real_lists_or_faking_them_properly.html

For more tips see Dive Into Accessibility

Top 10 ways to make a page/site more SEO friendly.

* Italicized items are from Google - http://www.google.com/support/webmasters/bin/answer.py?answer=35769

  1. Place the H1 tag as close to the opening body tag as possible. Use the H1 tag as a nametag for your site (I.E. Company name, Site name, Etc).
  2. Each page should have its own unique title tag. A good structure for the Title tage is: Website Name - Page Name
  3. Do not use the same color text on your page as the page's background color. This has often been used to keyword stuff a web page. Search engines can detect this and view it as spam.
  4. Make a site with a clear hierarchy and text links. Every page should be reachable from at least one static text link.
  5. Offer a site map to your users with links that point to the important parts of your site. If the site map is larger than 100 or so links, you may want to break the site map into separate pages.
  6. Create a useful, information-rich site, and write pages that clearly and accurately describe your content.
  7. Think about the words users would type to find your pages, and make sure that your site actually includes those words within it.
  8. Try to use text instead of images to display important names, content, or links. The Google crawler doesn't recognize text contained in images.
  9. Make sure that your TITLE and ALT tags are descriptive and accurate.
  10. Use a text browser such as Lynx to examine your site, because most search engine spiders see your site much as Lynx would. If fancy features such as JavaScript, cookies, session IDs, frames, DHTML, or Flash keep you from seeing all of your site in a text browser, then search engine spiders may have trouble crawling your site.