Data Representation Best Practices

HTML Fundamentals - Module 3

Introduction to Data Representation

When we talk about data representation on the web, we're discussing how to present information in ways that are accessible, meaningful, and useful to users. Tables often form the backbone of structured data representation, but the broader context involves choosing the right tool for each data scenario.

Think of data representation like serving a meal. The same ingredients (data) can be presented as a formal dinner (tables), a buffet (lists), or finger foods (inline elements) - with each presentation changing how the meal is experienced.

Key Principles of Data Representation

  • Clarity: Information should be immediately understandable
  • Accessibility: Data should be accessible to all users
  • Responsiveness: Data presentations should work across devices
  • Context: Related information should be grouped logically

Choosing the Right Structure for Your Data

Just as a carpenter selects different tools for different jobs, a web developer must choose the appropriate HTML elements for different types of data:

flowchart TD A[Data to Present] --> B{What type of data?} B -->|Tabular data with rows/columns| C[HTML Table] B -->|Simple list of items| D[Ordered or Unordered List] B -->|Key-value pairs| E[Definition List] B -->|Hierarchical data| F[Nested Lists] B -->|Single data points| G[Paragraph or Span elements]

Effective Table Usage for Data

Tables should be used for tabular data where there are clear relationships between rows and columns. They are not meant for page layout.

Use Tables When:

  • Displaying data with multiple variables across multiple entries
  • Comparing values across categories
  • Presenting statistical information
  • Showing timetables or schedules

Real-World Example: Product Comparison

<table>
  <caption>Smartphone Model Comparison - July 2025</caption>
  <thead>
    <tr>
      <th scope="col">Feature</th>
      <th scope="col">Model X</th>
      <th scope="col">Model Y</th>
      <th scope="col">Model Z</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">Display Size</th>
      <td>6.1"</td>
      <td>6.7"</td>
      <td>6.9"</td>
    </tr>
    <tr>
      <th scope="row">Battery Life</th>
      <td>12 hours</td>
      <td>18 hours</td>
      <td>24 hours</td>
    </tr>
    <tr>
      <th scope="row">Price</th>
      <td>$699</td>
      <td>$899</td>
      <td>$1099</td>
    </tr>
  </tbody>
</table>

Responsive Data Tables

One of the biggest challenges with HTML tables is making them responsive. Tables that look fine on desktop can become unusable on mobile devices.

Simple Approach: Horizontal Scrolling

<div style="overflow-x: auto;">
  <table>...</table>
</div>

Think of responsive tables like transforming furniture - a dining table that can fold down to become a coffee table when space is limited. The data remains the same, but the presentation adapts.

Beyond Tables: Alternative Data Representations

Sometimes tables aren't the best choice. Other HTML structures can be more appropriate:

Definition Lists for Key-Value Pairs

<dl>
  <dt>CPU</dt>
  <dd>Quantum Core i9-9900K, 8 cores, 5.0GHz</dd>
  
  <dt>RAM</dt>
  <dd>64GB DDR5-6000</dd>
  
  <dt>Storage</dt>
  <dd>2TB NVMe SSD</dd>
</dl>

Lists for Sequential or Categorical Data

<h3>Top 5 Programming Languages in 2025</h3>
<ol>
  <li>Python</li>
  <li>JavaScript</li>
  <li>Rust</li>
  <li>TypeScript</li>
  <li>Go</li>
</ol>

Using Semantic HTML5 Elements for Data

HTML5 introduced elements that enhance data presentation:

Example: Using Semantic Elements

<figure>
  <table>
    <tr>
      <th>Month</th>
      <th>Savings</th>
    </tr>
    <tr>
      <td>January</td>
      <td>$100</td>
    </tr>
    <tr>
      <td>February</td>
      <td>$80</td>
    </tr>
  </table>
  <figcaption>Fig.1 - First quarter savings.</figcaption>
</figure>

<details>
  <summary>User Activity (Q1 2025)</summary>
  <p>New users: 2,345</p>
  <p>Active users: 15,678</p>
</details>

Accessibility Considerations

Regardless of how you present data, accessibility must be a primary consideration:

Best Practices for Accessible Data

  • Use proper semantic elements for tabular data
  • Include captions and summaries where appropriate
  • Use header cells (<th>) with appropriate scope attributes
  • Test with screen readers to ensure your data is comprehensible
  • Maintain sufficient color contrast for all data elements

Accessibility is like universal design in architecture - a ramp benefits not just wheelchair users but also parents with strollers and many others. Similarly, accessible data benefits all users.

Real-World Example: Weather Dashboard

Current Conditions Using Definition List

<section aria-labelledby="current-conditions">
  <h2 id="current-conditions">Current Conditions</h2>
  
  <dl>
    <dt>Temperature</dt>
    <dd>72°F / 22°C</dd>
    
    <dt>Humidity</dt>
    <dd>45%</dd>
    
    <dt>Wind</dt>
    <dd>8 mph NW</dd>
  </dl>
</section>

Forecast Using Table

<section aria-labelledby="forecast">
  <h2 id="forecast">5-Day Forecast</h2>
  
  <div class="table-container">
    <table>
      <caption>Weather Forecast for Henderson, NV</caption>
      <thead>
        <tr>
          <th scope="col">Day</th>
          <th scope="col">Conditions</th>
          <th scope="col">High</th>
          <th scope="col">Low</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th scope="row">Thursday</th>
          <td>Sunny</td>
          <td>78°F</td>
          <td>65°F</td>
        </tr>
        <!-- More rows would go here -->
      </tbody>
    </table>
  </div>
</section>

Practical Exercise: Data Representation Challenge

Exercise: Create a Product Specifications Page

Create an HTML structure for a product specifications page that displays:

  • Basic product information using appropriate HTML elements
  • A comparison table with competing products
  • Technical specifications using an appropriate representation method

Focus on semantic correctness, accessibility, and choosing the right elements for each type of data.

Summary and Key Takeaways

Further Reading