jump to navigation

Avoid Self-closing Non-Voids in HTML December 15, 2011

Posted by Allen Manning in : HTML 5 , add a comment

In HTML, there are Void Elements and Non-Void Elements.  Also, depending on the version of HTML, there are different rules associated with how you close elements.

In some versions of HTML, elements need to be closed in a particular way.  Some versions of HTML also are flexible with the omission of elements- as they will re-write the DOM and imply them.

Once again with HTML we find ourselves in a multidimensional environment of rules and interpretations that can lead to confusion.

Definitions

Let’s start by looking at a couple of definitions:

Void Element: A defined sub-set of all HTML elements which can not contain any content.  It has no end tag.  For example, the HR and IMG elements are Void Elements.

Self-Closing Element: When an element is closed using standard XML syntax rules.  The classic ‘ />’.

Examples

<hr /> <!-- 1. self-closed void element -->
<hr> <!-- 2. non self-Closed Void Element -->
<span>content</span> <!-- 3. Closed Non-Void Element -->
<span /> <!-- 4. Self-Closed Non-Void Element -->
<span> <!-- 5. Non-Closed Non-Void Element -->

Do’s and Don’ts

Void Elements exist in all versions of HTML.  For most versions, self-closing is not needed.  Only with an XHTML doctype or when an XML parsing mode is indicated is self-closing a Void Element really needed.  HTML 5, for example, is tolerant of example 2, not self-closing a void element.

So, suffice it to say, developers are pretty safe with examples 1-3.

Example 4, Self-Closing Non-Voids, on the other hand must be avoided.  Developers must not think that just because it has no content, or it is likely to have no content, it is a Void Element. It is not valid HTML and depending on the browser will lead to confusing results.  Here is a great example of this problem, and the Validator errors that is associated with it.

Example 5, omitting closed elements, is tolerated in HTML 5.  It must be used judiciously and in situations in which bandwidth concerns are paramount.  Good HTML should be readable and relying on other developers who maintain the HTML to know the long list of HTML 5 - specific parsing rules is looking for trouble down the line.

Summary

Don’t self-close Non-Void elements, and only omit tags for a good reason.

A New Home for BrightAction October 14, 2011

Posted by Allen Manning in : BrightAction, Brightcove , add a comment

BrightAction (the open source Brightcove / Actionscript SDK) is happy to be living in its new home under the Brightcove Open Source GitHub Organization.  It’s new home is here: https://github.com/BrightcoveOS/BrightAction sitting alongside other very cool and powerful Brightcove - releated Open-Source projects.

What’t next for BrightAction?  Well quite a bit.  The immediate focus is on getting the Playlists into the mix, and after that?  Well, let’s just say that mobile on Flash seems like a nice fit right now.  There are many ideas and many opportunities- it is an exciting time!