</>HTML & CSS

HTML & CSS: Structure – code examples

Contents

Ordered and Unordered Lists

Structure#ul#ol#li#listCompare in all languages
Use case: Mark up bullet lists, navigation and step-by-step instructions semantically.
<!DOCTYPE html>
<style>body{font:16px system-ui,sans-serif;margin:12px;background:#fff;color:#222}
ul.check { list-style: none; padding-left: 0; }
ul.check li::before { content: "✔ "; color: seagreen; }
ol.schritte li { margin-bottom: 4px; }
ol.schritte li::marker { font-weight: 700; color: #e34f26; }
</style>
<h3>Shopping List</h3>
<ul class="check"><li>Milk</li><li>Bread</li><li>Coffee</li></ul>
<h3>Instructions</h3>
<ol class="schritte"><li>Create a file</li><li>Write HTML</li><li>Open in the browser</li></ol>

<ul> for unordered, <ol> for numbered lists with <li> entries. Navigation menus are lists as well. You control the appearance (symbols, counters) with list-style, ::marker and ::before.

Definition List and Table

Structure#dl#table#dictionary#mapCompare in all languages
Use case: Present key-value data (properties, price lists, profiles) clearly.
<!DOCTYPE html>
<style>body{font:16px system-ui,sans-serif;margin:12px;background:#fff;color:#222}
dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; }
dt { font-weight: 700; } dd { margin: 0; }
table { border-collapse: collapse; margin-top: 12px; }
th, td { border: 1px solid #bbb; padding: 4px 12px; text-align: left; }
th { background: #eee; }
</style>
<dl><dt>Name</dt><dd>Ada Lovelace</dd><dt>Profession</dt><dd>Mathematician</dd></dl>
<table>
  <tr><th>Country</th><th>Capital</th></tr>
  <tr><td>DE</td><td>Berlin</td></tr>
  <tr><td>FR</td><td>Paris</td></tr>
</table>

The counterpart of a map: <dl> with <dt> (key) and <dd> (value) for individual mappings, <table> for several records with the same columns (like a list of maps).

Table with Zebra Stripes

Structure#table#nth-child#zebra
Use case: Present data lists such as orders or rankings in a readable way.
<!DOCTYPE html>
<style>body{font:16px system-ui,sans-serif;margin:12px;background:#fff;color:#222}
table { border-collapse: collapse; width: 100%; max-width: 460px; }
caption { text-align: left; font-weight: 700; padding: 6px 0; }
th, td { padding: 8px 12px; text-align: left; }
thead th { background: #1f2937; color: #fff; }
tbody tr:nth-child(even) { background: #f3f4f6; }
tbody tr:hover { background: #e0e7ff; }
td.zahl, th.zahl { text-align: right; font-variant-numeric: tabular-nums; }
</style>
<table>
  <caption>Revenue by customer</caption>
  <thead><tr><th scope="col">Customer</th><th scope="col" class="zahl">Revenue</th></tr></thead>
  <tbody>
    <tr><th scope="row">Ada</th><td class="zahl">1,138.00 €</td></tr>
    <tr><th scope="row">Dana</th><td class="zahl">1,089.00 €</td></tr>
    <tr><th scope="row">Ben</th><td class="zahl">85.00 €</td></tr>
  </tbody>
</table>

caption, thead/tbody and th scope make the table accessible. :nth-child(even) provides stripes, tabular-nums aligns digits, numbers are right-aligned.