HTML Best Practices

When writing HTML, properly use whitespace in the code to ensure it is easy to read. Indent text as well to ensure relationships between elements are clear.

Add comments to provide clarity to your HTML documents. Comments begin with <!-- and end with -->, and result in the contents performing no action.

HTML Elements

Text Values - Tags

Styling Text Elements

Media Elements

HTML tables

A table can be created on an html page by placing its structure inside of a pair of <table> tags. Each row is contained within a pair of <tr> tags. Each data value should be contained with <td> tags. Header values should be enclosed with <th> tags. An example of what this looks like is provided below.

Okoorian family First Name Last Name
Person 1 Matthew Okoorian

Tables - Organization

The header row can be semantically labeled within a pair of tags using <thead>

Below the header row, table data can be organized with a tag called <tbody>

Finally, the footer row (where there could be totals or other information) can be enclosed in a tags set to <tfoot>.

Attributes

HTML Organizational Structure

Standard Organizing Tags

Semantic HTML

Semantic HTML makes reading HTML easier by ensuring the intention behind material is clearer. Here are some examples of semantic elements in the order they often appear.

  1. <header> - often used for a top bar on the page.
  2. <nav> - often used to frame a section where links to other content may be placed.
  3. <main> - used to contain the primary body of a webpage.
  4. <section> - used to contain a portion of the main, seperates portions of the page into discrete areas or topics.
  5. <article> - used to tag an item that stands on its own. Examples include articles, blogs, comments, magazines, etc.
  6. <aside> - used to tag information that enhances main information, but isnt critical. Examples include Bibliographies, Endnotes, Comments, Quotes, Additional Information.
  7. <figure> - used for media like pictures or video.
  8. <figcaption> - used to place text below a figure. Encompasses a text element. Usually enclosed within a figure tag alongside an img.
  9. <footer> - used to contain a block at the bottom of the page with additional navigation or contact details.

Element Attributes

HTML elements can be given additional attributes to effect how they are used. Attributes are set by placing within the opening tag a Property='Value'.
Example: <h1 id='test123'>

Common Attributes

  1. id - used to give specific element a unique identifier for reference elsewhere. Value should be unique.
  2. class - used to give an element a shared identifier so it may share configuration between itself and elements of a same class.