Posted By

Rar on 10/27/13


Tagged

basic css javascript template html with feature comments CSS3 Website html5


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

Rar
icnovaro


HTML5 Basic Template (w/ Comments)


 / Published in: HTML
 

Extremely helpful to anyone who is looking to improve performance and follow best practices in HTML/CSS

  1. <!DOCTYPE html>
  2.  
  3. <!--
  4. HTML5 is the latest evolution
  5. of standards that defines HTML.
  6. -->
  7.  
  8. <!-- The best way to specify language in HTML5. -->
  9.  
  10. <html lang="en">
  11.  
  12. <head>
  13.  
  14. <!-- This is easier to type, and remember than http-equiv. -->
  15.  
  16. <meta charset="utf-8">
  17.  
  18. <!--
  19. If you want to add more METAs,
  20. just know not to go overboard
  21. with them.
  22.  
  23. They're not relied on a lot
  24. nowadays.
  25.  
  26. I do suggest still using a
  27. few of them though, like
  28. "charset."
  29. -->
  30.  
  31. <!--
  32. Stylesheets prohibit progressive
  33. rendering until they're all
  34. downloaded.
  35.  
  36. Keep them inside the HEAD to
  37. eliminate this problem.
  38.  
  39. NEVER apply CSS in-line internally,
  40. always externally.
  41.  
  42. Drop the 'type' attribute in HTML5
  43. for optimization.
  44. -->
  45.  
  46. <link rel="stylesheet" href="style\">
  47. <link rel="icon" href="image\">
  48.  
  49. <!-- Appears on the tab in the browser. -->
  50.  
  51.  
  52. <!--
  53. As you may or may not have already
  54. realized, HTML5 isn't supported in
  55. older versions of internet explorer.
  56.  
  57. To compensate for this, you should
  58. use html5shiv to add support to
  59. HTML5.
  60.  
  61. The code used to do this, will only
  62. work inside the HEAD, however.
  63.  
  64. And for performance sake, this should
  65. go after the CSS.
  66. -->
  67.  
  68. <!--[if lt IE 9]>
  69. <script src="dist/html5shiv.js"></script>
  70. <![endif]-->
  71.  
  72. </head>
  73.  
  74. <!--
  75. Use class instead of id
  76. whenever possible.
  77.  
  78. Id have more "weight"
  79. than class when it comes
  80. to applying styles.
  81.  
  82. This can prevent some CSS
  83. classes applied on elements
  84. inside the container from
  85. working properly.
  86. -->
  87.  
  88. <body><div class="container">
  89.  
  90. <!--
  91. Despite the addition of new
  92. elements that justifably
  93. captures a lot of DIV's territory,
  94. you can still use them.
  95.  
  96. The best practice is to use
  97. DIVs when there is no other
  98. more semantically appropiate
  99. element that suits your
  100. purpoe.
  101. -->
  102.  
  103. <header>
  104.  
  105. <hgroup>
  106. <h1>Title</h1>
  107. <h2>Slogan</h2>
  108. </hgroup>
  109.  
  110. </header>
  111.  
  112. <!--
  113. In CSS, don't do:
  114.  
  115. nav ul {
  116.  
  117. }
  118.  
  119. Instead, you should do:
  120.  
  121. #navigation {
  122.  
  123. }
  124.  
  125. But you can still do:
  126.  
  127. header {
  128.  
  129. }
  130.  
  131. if you need only one.
  132.  
  133. Reduce those HTTP Request!
  134. -->
  135.  
  136. <nav><ul class="navigation">
  137.  
  138. <!--
  139. All text inside a HTML element
  140. should be lowercase to make it
  141. easier to read.
  142. -->
  143.  
  144. <li class="active"><a href="home.html">Home</a></li>
  145. <li><a href="contact.html">Contact</a></li>
  146. <li><a href="about.html">About</a></li>
  147.  
  148. </ul></nav>
  149.  
  150. <div class="main">
  151.  
  152. <!--
  153. Why would I use ARTICLE
  154. when it should be SECTION
  155. instead?
  156.  
  157. From the specs, doing that
  158. isn't the true, intended
  159. purpose of that element.
  160. -->
  161.  
  162. <article>
  163.  
  164. <!--
  165. Utilize :first-child, :last-child and
  166. :nth-child to get non-classed elements
  167. for CSS.
  168. -->
  169.  
  170. <hgroup>
  171. <h1>Title</h1>
  172. <h3>Author</h3>
  173. </hgroup>
  174.  
  175. <!--
  176. Don't do this:
  177.  
  178. <p>Message
  179.  
  180. <p>Message
  181.  
  182. You should close those tags.
  183. -->
  184.  
  185. <p>Message</p>
  186. <p>Message</p>
  187. <p>Message</p>
  188.  
  189. <footer>Date</footer>
  190.  
  191. </article>
  192.  
  193. </div>
  194.  
  195. <footer>Copyright</footer>
  196.  
  197. <!--
  198. Scripts prevents progressive rendering, parallel
  199. downloads for all content below.
  200. Move them to the bottom for faster page loading.
  201.  
  202. JQuery is a fast, small, and feature-rich
  203. JavaScript library. "Write less, do more."
  204. -->
  205.  
  206. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  207.  
  208. <!--
  209. You'll need a fallback for when the website
  210. you're retrieving JQuery from, fails.
  211.  
  212. There are other ways to do this than the
  213. one I'm coding here (protocol-less URLS).
  214. -->
  215.  
  216. <script>window.jQuery || document.write('<script src="js/jquery-2.0.0.min.js">\x3C/script>')</script>
  217.  
  218. <!--
  219. Finally, always comment your code.
  220. You'll be suprised at how much
  221. faster you'll from it.
  222. -->
  223.  
  224. </div></body>
  225. </html>

Report this snippet  

You need to login to post a comment.