Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Semantic HTML 5

Semantic HTML 5

Using HTML5 semantically.

Terrence Ryan

May 03, 2012
Tweet

More Decks by Terrence Ryan

Other Decks in Technology

Transcript

  1. Agenda •  Introduction •  Overview of Semantics •  New Semantic

    elements •  New Semantic attributes •  New Form Input Types •  New Form attributes •  Pitfalls •  Conclusions
  2. What do we mean by Semantic HTML •  HTML where

    proper elements are used –  <p> denotes paragraph –  <ul> denotes an list of items, where the order is not important –  <address> contains address information –  <div> and <span> are used to describe information •  HTML where extraneous elements are not misused –  No <p> for line breaking –  No <blockquote> for indentation –  No <h1> for big text •  HTML without presentation information –  No <font>, <b>, <i> tags –  No inline styles
  3. Semantic HTML is a moving target •  Not Boolean • 

    Not always objective •  A continuum
  4. Semantic HTML <body  background="css/bg.png">   <font  face="Calibri”><center>   <table  width="800"

     bgcolor="#FFFFFF"  border="10"   bordercolor="#FFFFFF">   <tr><td>   <table  width="100%"  bgcolor="#f0f0f0"  border="0“>     <tr>   <td><h1>   <font  face="Palatino  Linotype">The  Awesome  Blog  of   Awesome</font>   </h1>   </td>   </tr>   <tr>           <td  align="right"><p><i>Awesome  is  a  State  of  Mind</i></ p></td>   </tr>   </table>   <body>   <div  id="header">   <h1>The  Awesome  Blog  of   Awesome</h1>   <p  class="tagline">   Awesome  is  a  State  of   Mind   </p>   </div>   RELATIVELY UNSEMANTIC RELATIVELY SEMANTIC
  5. HTML5 adds more semantics <body>          <header>

                             <h1>The  Awesome  Blog  of  Awesome</h1>                          <p>Awesome  is  a  State  of  Mind</p>          </header>          <nav>            <ul>                          <li><a  href="">Home</a></li>                          <li><a  href="">Blog</a></li>                          <li><a  href="">About</a></li>                          <li><a  href="">Contact</a></li>                  </ul>          </nav>
  6. Header <div  id="header">            <h1>The  Awesome

     Blog  of  Awesome</h1>    <p  class="tagline">Awesome  is  a  State  of  Mind</p>   </div>   <header>            <hgroup>                          <h1>The  Awesome  Blog  of  Awesome</h1>                          <h2>Awesome  is  a  State  of  Mind</h2>            </hgroup>   </header>   HTML 5 PREVIOUSLY
  7. It’s for grouping related headers, that don’t spawn their own

    node in the outline <hgroup>    <h1></h1>    <h2></h2>   </hgroup>     Hgroup
  8. Effect of hgroup H1  –  Awesome  Blog  of  Awesome  

    H2  -­‐  Awesome  is  a  State  of  Mind   H2  -­‐  Recent  Posts   H3  I  Made  a  Post  Thingie   H3  My  Thoughts  are  made  manifest       H1  –  Awesome  Blog  of  Awesome   H2  Recent  Posts   H3  I  Made  a  Post  Thingie   H3  My  Thoughts  are  made  manifest       NO HGROUP WITH HGROUP
  9. Outlines •  Outlines seem really important to the people who

    push semantic HTML 5 •  Are they really important? – Today: No – Tomorrow: Who knows? •  But this is a semantically correct way of reducing classes and extraneous divs 22  
  10. Footer <div  id="footer”>    <p>Copyright  2011  -­‐  Terry  Ryan</p>  

    </div>   <footer>            <p>Copyright  2011  -­‐  Terry  Ryan</p>   </footer>   HTML 5 PREVIOUSLY
  11. Navigation <div  id="nav">      <ul>        

     <li><a  href="">Home</a></li>          <li><a  href="">Blog</a></li>          <li><a  href="">About</a></li>          <li><a  href="">Contact</a></li>      </ul>   </div>   <nav>    <ul>          <li><a  href="">Home</a></li>          <li><a  href="">Blog</a></li>          <li><a  href="">About</a></li>          <li><a  href="">Contact</a></li>      </ul>   </nav>   PREVIOUSLY HTML 5
  12. Articles <div  class="post”>    <div  class="postheader">      <h3><a  href="">I

     Scream  My  Thoughts</a></h3>      <p  class="date">August  10,  2011</p>    </div>    <p>You  probably  haven't  heard  of  them  duis</p>   </div>   <article>    <header>      <h1><a  href="">I  Scream  My  Thoughts</a></h1>      <time>August  10,  2011</time>    </header>    <p>You  probably  haven't  heard  of  them  duis  </p>   </article>   PREVIOUSLY HTML5
  13. Date and Time •  <time datetime={datetime} pubdate>Human Readable String</time> – Datetime

    •  Date: 2011-09-20 •  Datetime: 2011-09-20T20:00Z •  Datetime: 2011-09-20T20:00+00:00 – Pubdate •  Used with article to denote that this particular time is the publication date.
  14. Content <div  class=”content”>    <div  class="post”>    ...    </div>

       <div  class="post”>    ...    </div>    <div  class="post”>    ...    </div>   </div>   <div  class=”content”>    <article>    ...    </article>    <article>    ...    </article>    <article>    ...    <article>   </div>     PREVIOUSLY HTML5
  15. Also can be correct <div  class=”content”>    <div  class="post”>  

     ...    </div>    <div  class="post”>    ...    </div>    <div  class="post”>    ...    </div>   </div>   <section  class=”content”>    <article>    ...    </article>    <article>    ...    </article>    <article>    ...    <article>   </section>     PREVIOUSLY HTML5
  16. Umm That’s great, but frankly not that much of a

    difference. How is this better?
  17. Benefit 1    </div>    </div>        

      </div>   <div  id=“footer”>   </div>   </body>      </div>    </article>           </section>   <footer>   </footer>   </body>     BEFORE THESE ELEMENTS AFTER
  18. Main Page Archive Page Post Page Article Article Article <article>

       <header>      <h1><a  href="">I  Made  a  Post  Thingie</a></h1>      <time  datetime="2011-­‐09-­‐02">September  2,  2011</time>    </header>    <img  src="img/captain-­‐awesome.jpg"  width="300"  height="200"  alt="Image  of  Captain  Awesome"  />    <p>DIY  ea  nulla  photo  booth  tempor  occaecat,  velit  nihil  mixtape  scenester.      Irony  laboris  echo  park,  wolf  officia  vice  cupidatat  labore  butcher  freegan      farm-­‐to-­‐table  nisi  velit  aliqua  gluten-­‐free.  Aliquip  nesciunt  assumenda,      wayfarers  seitan  wolf  reprehenderit  nulla  twee  sartorial  dolore  food  truck      voluptate  ex  vinyl.  Aliquip  ex  enim,  irony  terry  richardson  trust  fund  consectetur      fap  pariatur  dolor.  Lo-­‐fi  nulla  whatever  mlkshk,  banksy  american  apparel  carles      adipisicing  incididunt  wolf  photo  booth  hipster.  Wayfarers  four  loko  ex  cosby  sweater,      adipisicing  sartorial  non  cardigan  craft  beer  cillum  reprehenderit  terry  richardson      3  wolf  moon  mollit.  Ethical  ut  labore  beard,  3  wolf  moon  duis  readymade  assumenda      hipster  tofu  mcsweeney's  master  cleanse.</p>   </article>   article  header  h1  
  19. •  Add “data-” to anything to make your content contain

    data •  Uses? •  Scritping •  Microformats •  jQuery Mobile •  Perhaps future Search Engine hints. <p  data-­‐firstname=“Terry”  data-­‐lastname=“Ryan”>Terry  Ryan</p>   data
  20. •  Allows any text to be user editable, not just

    input and textareas. •  Uses •  Better CMS systems •  Comment previews <p  contenteditable="true”  class="comment">Comment</p>   contenteditable
  21. •  Allows any field that is user editable to trigger

    the browser’s spellcheck interface •  Uses: •  No one spellchecks anything they post on the web •  But you will have the moral high ground to point out on your site they could have. <p  contenteditable="true"  spellcheck="spellcheck"  class="comment">Comment</p>   spellcheck
  22. •  Support is spotty •  Browser vendors tend to round,

    add magnifying glass, etc. <input  type=“search”  name=“search”  />   Search
  23. •  Provides validation •  Provides email keyboard on iOS devices.

    <input  type=“email”  name=“email”  />   Email
  24. Provides keypad on iOS and Android devices. Provides a stepper

    on desktops Takes attributes: –  Min/Max –  Step <input  type=“number”  name=“cost”  />     Number
  25. •  Provides a set of values •  The slider allows

    you to pick one •  Not terribly precise •  Takes attributes: •  Min/Max •  Step <input  type=“range”  name=“volume”  />   Range
  26. •  Provides validation •  On Opera •  Displays a data

    picker •  On Safari/Chrome •  Displays ticker •  IE •  Dashes your hopes and dreams the way only IE can <input  type=“date”  name=“dob”  />   Date
  27. Output Semantically correct placeholder for calculated values. Can also be

    used a label for input type=“slider” <output  />  
  28. Output in Action <form  class="order">        <label  for="quantity">Quantity:</label>

           <input  id="quantity"  name="quantity"  type="number"  value="1"  onChange="calc()"  />        <br  />        <label  for="price">Price:  </label>        <input  id="price"  name="price"  type="number"  value="19.99"  disabled  />        <br  />        <label  for="total">Total:  </label>        <output  id="total"  name="total"    />        <br  />   </form>         <script  type="application/javascript">   function  calc(){    var  quantity  =  document.getElementById("quantity").value;    var  price  =  document.getElementById("price").value;      var  total  =  document.getElementById("total");    total.value  =  Math.round(quantity  *  price  *  100)/100;     }   </script>  
  29. progress Could be used to indicate progress through a multistep

    form Could be programmatically changed to indicate progress of program <progress  min=“100”  value=“20”>20%</progress>  
  30. On Tableless designs Don’t use tables for layout, use CSS.

    Tables are for tabular data. They are just one of the tools in your toolkit. Holzschlag Zeldman Shea Icons by: http://www.ngenworks.com/
  31. What people heard Don’t use tables for layout, use CSS.

    Tables are for tabular data. They are just one of the tools in your toolkit. Holzschlag Zeldman Shea Icons by: http://www.ngenworks.com/
  32. I’m not saying Don’t use div’s when there are semantic

    elements that make sense. Div’s are still good for denoting things that have no semantic equivalent
  33. I’m not saying Don’t use div’s when there are semantic

    elements that make sense. Div’s are still good for denoting things that have no semantic equivalent
  34. New Elements •  Supported on most browsers •  If they

    are not supported, can be enabled using the HTML 5 Shiv
  35. New Attributes •  Supported on most browsers •  If they

    are not supported, they have no impact.
  36. New Form Inputs •  Support wildly varies •  If they

    are not supported, they have no impact.
  37. New Form Elements •  Support wildly varies •  Mimic things

    that have been provided by JavaScript for years
  38. For Future Reference •  HTML 5 General – http://diveintohtml5.org – http://html5doctor.com • 

    HTML5 Semantics – http://diveintohtml5.org/semantics.html •  HTML 5 Forms – http://wufoo.com/html5 – http://diveintohtml5.org/forms.html •  HTML Status – http://caniuse.com 103