dive into mark

You are here: dive into markArchivesApril 2002HTML structural elements

Tuesday, April 23, 2002

HTML structural elements

Steven Vore: HTML Learning o’ the Day. EM is a ‘phrase element’. That means that this construct … isn’t quite right: <p><em>text<p>more text</em><p>. Yup, that’s wrong, but the root of your confusion isn’t the EM tag, it’s the P tag. P is a block-level element; once you open a P tag, you’re starting a new block. Tags that are opened in a block must be closed in the same block, if they are closed at all. This would make more sense if you closed your P tags, because then you could read it like the outline that it is:

<p>
  <em>
    text
  </em>
</p>
<p>
  <em>
    more text
  </em>
</p>

Skipping the end P tag is acceptable in HTML, but it can lead to confusion (for you, not your browser) when reading your page source later. However, XHTML requires all tags to be closed in a strict hierarchy like the above example.

You can learn a lot about your HTML coding by running your page source through HTML Tidy. HTML Tidy can insert end tags, add missing DOCTYPEs, convert legacy or proprietary tags, clean up the mess that Word outputs when “saving as HTML”, warn of common accessibility problems (like missing ALT tags), auto-indent like the example above… even migrate your entire web page to XHTML. It’s an amazing little utility, and it’s open source.

Filed under , ,

Respond privately

I am no longer accepting public comments on this post, but you can use this form to contact me privately. (Your message will not be published.)



Recent Stuff For You, Special Price Stay Here
  • Greasemonkey Hacks
Good Stuff Buy The Cow Go Away
Dive Into Python
Powered by Google Drink The Milk Don't Steal

 

posts / comments
© 2001-8 Mark Pilgrim