Note: You are currently viewing documentation for Moodle 1.9. Up-to-date documentation for the latest stable version is available here: Semantic HTML.

Semantic HTML: Difference between revisions

From MoodleDocs
 
(35 intermediate revisions by the same user not shown)
Line 1: Line 1:
== The case for semantic HTML ==
== The case for semantic HTML ==


It is easy to create HTML that ''works'', but current best practice suggests that creating valid and '''Semantic HTML''' is an important goal for various reasons including user experience and [[accessibility]].  
It is easy to create HTML that ''works'', but current best practice suggests that creating valid and Semantic HTML is an important goal for various reasons including [[Usability|usability]] and [[Accessibility|accessibility]].  


Unfortunately, while validation is a relatively easy task to understand and achieve, creating Semantically correct HTML is a lot more subjective and open to debate.
Unfortunately, while validation is a relatively easy task to understand and achieve, creating semantically correct HTML is a lot more subjective and open to debate.


== Examples for semantic HTML ==
== Examples for semantic HTML ==


For some concrete examples how to make Moodle HTML more semantic you might have a look at this work in progress: [[User:Frank Ralf/Semantic HTML1]]. --[[User:Frank Ralf|Frank Ralf]] 11:26, 26 May 2009)
Here are some examples of non-semantic HTML taken from the current Moodle markup (layout and styling is done with CSS which isn't shown here).


=== List instead of DIVs ===
BAD:
<code php>
<div class="depth0">
  <a href="#" name="d16">
    <img id="vh_div16indicator" src="pix/closed.gif" alt="Closed folder">
      Security
  </a>
</div>
<span id="vh_div16"></span>
</code>
GOOD:
<code php>
<li class="closed"><a href="#">Security</a></li>
</code>
(Example taken from Moodle's ''Site Administration'' block, see [[User:Frank Ralf/Semantic HTML1]].)
=== Indentation without ''spacer.gif'' ===
BAD:
<code php>
<table class="categorylist">
<tbody>
  <tr>
    <td class="category indentation" valign="top">
      <img class="spacer" src="pix/spacer.gif" alt="" height="10" width="20">
      <br>
    </td>
    <td class="category name" valign="top">
      <a href="/course/category.php?id=3">Quizzes</a>
    </td>
    <td class="category number" valign="top">1</td>
  </tr>
</tbody>
</table>
</code>
GOOD:
<code php>
<ul>
  <li><a href="/course/category.php?id=3">Quizzes</a>1</li>
</ul>
</code>
(Example from Moodle's ''Course Category'' list, see [[User:Frank Ralf/Semantic HTML4]].)
== Separating structure and styling ==
Don't use inline styles but put any styling information in a separate CSS.
BAD:
<code php>
<td style="width:180px" id="left-column">
</code>
GOOD:
<code php>
<style type="text/css">
<!--
td#left-column {width: 180px;}
-->
</style>
<td id="left-column">
</code>
(Example taken from one of Moodle's standard themes.)
== Avoid "divitis" and "classitis" ==
"The div tag is a block-level element that defines a section within a document. Divs are thus suitable for building the structure of Web pages. The div tag is also used to describe content that cannot be properly described by other more semantic tags. When developers do not understand the semantic meaning of other block-level elements, they often add more div tags than are needed."
Source: [http://www.smashingmagazine.com/2009/04/08/from-table-hell-to-div-hell/ "Table Layouts vs. Div Layouts: From Hell to… Hell?"] by Geir Wavik, from ''Smashing Magazine''
Another disease in the CSS world is called "classitis", the excessive use of classes (mainly for non-semantic reasons). For examples and hints to avoid this see [http://www.cssnewbie.com/combating-classitis/ "Combating Classitis with Cascades and Sequential Selectors"] by Rob Glazebrook.
Here's an example for a meaningless class:
<code php>
<a class="link" href="admin/register.php">...</a>
</code>


== Further resources ==
== Further resources ==


=== Online: ===
=== Online: ===
* [[Semantic Web]]
 
* [[Microformat]]
* [http://diveintomark.org/archives/2003/08/29/semantics Mark Pilgrim's ''Won’t somebody please think of the gerbils?'']
* [http://diveintomark.org/archives/2003/08/29/semantics Mark Pilgrim's ''Won’t somebody please think of the gerbils?'']
* [http://www.standards-schmandards.com/index.php?2006/03/03/36-wysiwyg-editor-test An evaluation of WYSIWYG editors (including TinyMCE) for their production of valid, semantic & accessible HTML]
* [http://www.standards-schmandards.com/index.php?2006/03/03/36-wysiwyg-editor-test An evaluation of WYSIWYG editors (including TinyMCE) for their production of valid, semantic & accessible HTML]
Line 33: Line 117:
=== Books: ===
=== Books: ===


* [http://www.zeldman.com/dwws/ Designing with Web Standards, 2nd ed.] by Jeffrey Zeldman
* [http://www.zeldman.com/dwws/ Designing with Web Standards, 2nd ed.] by Jeffrey Zeldman - This book is the single most useful source for getting you on track for writing semantic code. Highly recommended!


== See also ==
== See also ==


* [[Development:XHTML]]
* [[Accessibility]]
* [[Accessibility]]
* [[Usability FAQ]]
* [[Usability FAQ]]
* [[CSS FAQ]]
* [[CSS FAQ]]
* [http://www.sitepoint.com/blogs/2010/03/16/the-tragic-comedy-that-is-rich-text-editing-on-the-web/ "The Tragic Comedy that is Rich Text Editing on the Web"] - SitePoint blog
* For more examples how to make Moodle HTML more semantic you might also have a look at this work in progress: [[User:Frank Ralf/Semantic HTML1]].


[[Category:Developer]]
[[Category:Developer]]
[[Category:Accessibility]]
[[Category:Accessibility]]
[[Category:Usability]]
[[Category:Usability]]

Latest revision as of 15:24, 16 March 2010

The case for semantic HTML

It is easy to create HTML that works, but current best practice suggests that creating valid and Semantic HTML is an important goal for various reasons including usability and accessibility.

Unfortunately, while validation is a relatively easy task to understand and achieve, creating semantically correct HTML is a lot more subjective and open to debate.

Examples for semantic HTML

Here are some examples of non-semantic HTML taken from the current Moodle markup (layout and styling is done with CSS which isn't shown here).

List instead of DIVs

BAD:

 <a href="#" name="d16">
   <img id="vh_div16indicator" src="pix/closed.gif" alt="Closed folder">
     Security
 </a>

GOOD:

  • <a href="#">Security</a>
  • (Example taken from Moodle's Site Administration block, see Frank Ralf/Semantic HTML1.)

    Indentation without spacer.gif

    BAD:

    <tbody> </tbody>
         <img class="spacer" src="pix/spacer.gif" alt="" height="10" width="20">
         
         <a href="/course/category.php?id=3">Quizzes</a>
    
    1

    GOOD:

    • <a href="/course/category.php?id=3">Quizzes</a>1

    (Example from Moodle's Course Category list, see Frank Ralf/Semantic HTML4.)


    Separating structure and styling

    Don't use inline styles but put any styling information in a separate CSS.

    BAD:

    GOOD: <style type="text/css"> </style>

    (Example taken from one of Moodle's standard themes.)

    Avoid "divitis" and "classitis"

    "The div tag is a block-level element that defines a section within a document. Divs are thus suitable for building the structure of Web pages. The div tag is also used to describe content that cannot be properly described by other more semantic tags. When developers do not understand the semantic meaning of other block-level elements, they often add more div tags than are needed."

    Source: "Table Layouts vs. Div Layouts: From Hell to… Hell?" by Geir Wavik, from Smashing Magazine

    Another disease in the CSS world is called "classitis", the excessive use of classes (mainly for non-semantic reasons). For examples and hints to avoid this see "Combating Classitis with Cascades and Sequential Selectors" by Rob Glazebrook.

    Here's an example for a meaningless class:

    <a class="link" href="admin/register.php">...</a>

    Further resources

    Online:

    Books:

    See also

    • For more examples how to make Moodle HTML more semantic you might also have a look at this work in progress: Frank Ralf/Semantic HTML1.