• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 24. Testing and Debugging Web Pages > Checking the Easy Stuff: XHTML

Checking the Easy Stuff: XHTML

If you’re making the jump to XHTML, it’s easy to miss a few of its syntax rules. Make sure you check them first.

To check the easy stuff with XHTML

  • Be sure all attribute values are enclosed in straight, not curly, quotes. If the value itself contains quotes, use references (see page 340). Also note that a value can contain single quotes if the value is enclosed in double quotes, or double quotes if the value is enclosed in single quotes (Figures 24.5 and 24.6).

    Figure 24.5. If an attribute’s value contains a single quote, you can just enclose it in double quotes as usual.

    <img src="jungle.jpg" alt="Llumi's jungle" />
    

    Figure 24.6. If an attribute’s value contains double quotes, either use references (top), or enclose the attribute value in single quotes (bottom).

    <img src="cookie.jpg" alt="Cookie's saying
    &quot;Enough!&quot;" />
    
    <img src="tough_llumi.jpg" alt='Llumi replies, "This
    is _my_ jungle."' />
    

  • Make sure all elements have opening and closing tags, or one combination tag (with a final /). Always put a space before the / to ensure compatibility with older browsers.

  • Don’t combine opening and closing tags for elements that usually have content. For example, while <p /> is technically correct in XHTML, browsers won’t always know what to do with it. In the same vein, don’t use separate opening and closing tags for empty elements as in <img src="woody.gif" alt="cat"> </img>. Again, while this is perfectly valid XHTML, browsers will be confused (Figures 24.7 and 24.8).

    Figure 24.7. Here are two examples of valid XHTML that will give most browsers a headache.

    <p />
    
    <img src="jungle.jpg" alt="Llumi's jungle" >
    </img>
    							

    Figure 24.8. Instead, don’t combine the opening and closing tags of elements that aren’t usually empty (like p) and don’t use individual opening and closing tags for elements that are usually empty (like img).

    <p></p>
    
    <img src="jungle.jpg" alt="Llumi's jungle" />
    							

  • Be careful about case. All elements, attributes, and predefined values should be in lowercase.

  • Don’t leave out the # when specifying hexadecimal colors.

  • If symbols or accented characters are not displaying properly, see Chapter 20, Symbols and Non-English Characters.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint