HTML 5 is somewhat looser in its requirements for markup compared to XHTML, allowing a number of shortcuts:
- Tags can be written uppercase, lowercase, or in mIxEd case.
- You can drop a lot of closing tags:
</p>(in most cases),
</html>are not required.
- Attribute values only need to be quoted if they contain spaces or some non-alphanumeric characters (such as a question mark). So
<div id=wrapper>is legitimate, as is
<img src=assets/images/falls.jpg …>but
<img alt=Angel Falls …>is not.
typeattribute is required on scripts or stylesheets: a link to a CSS file can be written as
<link rel=stylesheet href=styles.css>
You will see these shortcuts used in some code examples on this blog in order to save space. If web development is new to you I strongly suggest that you stick to the basic rules for writing HTML code. (Your web page will continue to work fine, and the code will likely be easier for you to read). Once you’re familiar with HTML, you can start to introduce exceptions. You’ll also find that many text editors and IDEs, such as DreamWeaver will fight any attempts at shortcuts, automatically closing tags or suggesting there are errors on the page unless you change their preference settings.
Enjoy this piece? I invite you to follow me at twitter.com/dudleystorey to learn more.