The time Element β Machine-Readable Dates
The <time> element marks a date, time, or duration that is readable by both humans and machines. The visible content is human-friendly text; the datetime attribute provides the machine-readable ISO 8601 value that search engines and calendar apps can parse.
<!-- Date only: YYYY-MM-DD -->
<p>Published on <time datetime="2026-04-15">15 April 2026</time></p>
<!-- Date with time: YYYY-MM-DDTHH:MM -->
<p>Event starts at <time datetime="2026-06-20T09:30">20 June 2026 at 9:30 AM</time></p>
<!-- Date with time and timezone offset -->
<p>Webinar: <time datetime="2026-07-01T14:00+01:00">1 July 2026, 2pm BST</time></p>
<!-- Year-month only -->
<p>Card expires: <time datetime="2028-09">September 2028</time></p>
<!-- Duration: P = period, 1H30M = 1 hour 30 minutes -->
<p>Course length: <time datetime="PT1H30M">1 hour 30 minutes</time></p>
<!-- Without datetime: visible text IS the machine value -->
<p>The event is on <time>2026-11-05</time></p>
<time datetime=""> to display publication dates in search result snippets. Social media previews, RSS readers, and calendar apps all consume the machine-readable value. Without it, they must guess the date from the page text β often incorrectly.
The mark Element β Highlighted Text
The <mark> element marks text that is highlighted or relevant to the user's current context. It is not emphasis (<em>) or strong importance (<strong>) β it indicates relevance, like a search result match or a passage you want to draw attention to because of the user's specific query.
<!-- Search result: user searched for "semantic HTML" -->
<p>
This tutorial explains what <mark>semantic HTML</mark> is, why it matters,
and how to convert <mark>semantic HTML</mark> div soup into properly
structured markup.
</p>
<!-- Highlighted passage in an article -->
<p>The most important rule when writing forms is:
<mark>never send passwords or sensitive data via GET</mark>.
</p>
<!-- Key term highlighted on first mention -->
<p>The <mark>Document Object Model (DOM)</mark> is the browser's in-memory
representation of the HTML page.</p>
By default browsers render <mark> with a yellow background. You can override this with CSS:
mark {
background-color: #fff3cd;
color: inherit;
border-radius: 2px;
padding: 0 2px;
}
/* Highlight search matches in a different colour */
.search-result mark {
background-color: #cce5ff;
}
details and summary β Native Collapsible Accordion
The <details> element creates a native collapsible disclosure widget with no JavaScript required. The <summary> child provides the visible heading that users click to expand or collapse the content.
<!-- Collapsed by default -->
<details>
<summary>What is the difference between GET and POST?</summary>
<p>GET appends form data to the URL as a query string β making it visible in
the address bar and browser history. POST sends data in the HTTP request body,
keeping it out of the URL. Use GET for searches and filters; use POST for
logins, registrations, and any sensitive data.</p>
</details>
<!-- Open by default: the open attribute -->
<details open>
<summary>HTML course prerequisites</summary>
<ul>
<li>No prior coding experience needed</li>
<li>A text editor (VS Code recommended)</li>
<li>A modern web browser</li>
</ul>
</details>
<!-- FAQ section using details/summary -->
<section class="faq">
<h2>Frequently Asked Questions</h2>
<details>
<summary>Is this course free?</summary>
<p>Yes, all tutorials on ylearner are completely free.</p>
</details>
<details>
<summary>Do I get a certificate?</summary>
<p>Certificates are planned for a future release.</p>
</details>
<details>
<summary>How long does the HTML course take?</summary>
<p>The full course takes approximately 20β30 hours depending on your pace.</p>
</details>
</section>
details {
border: 1px solid #dee2e6;
border-radius: 6px;
margin-bottom: 0.75rem;
}
summary {
padding: 0.75rem 1rem;
font-weight: 600;
cursor: pointer;
list-style: none; /* remove default triangle in some browsers */
}
summary::-webkit-details-marker { display: none; } /* Safari */
/* Custom triangle indicator */
summary::before {
content: "βΆ";
margin-right: 0.5rem;
font-size: 0.75rem;
transition: transform 0.2s;
display: inline-block;
}
details[open] summary::before {
transform: rotate(90deg);
}
details[open] summary {
border-bottom: 1px solid #dee2e6;
}
details > *:not(summary) {
padding: 1rem;
}
The progress Element
The <progress> element represents a task completion bar. Use it to show the progress of a file download, form wizard step completion, or any operation with a defined end state.
valueβ current progress (must be between 0 and max).maxβ the total amount when complete (defaults to 1 if omitted).- Omitting
valuecreates an indeterminate progress bar (browser-animated spinner or pulsing bar).
<!-- 60% complete -->
<label for="course-progress">Course progress: 60%</label>
<progress id="course-progress" value="60" max="100">60%</progress>
<!-- File download: 3.2 MB of 10 MB -->
<label for="dl-progress">Downloading: 3.2 MB / 10 MB</label>
<progress id="dl-progress" value="3.2" max="10">32%</progress>
<!-- Indeterminate: no value (operation running but total unknown) -->
<label for="ind-progress">Processingβ¦</label>
<progress id="ind-progress">Processingβ¦</progress>
<progress> and </progress> is fallback for browsers that don't support the element. Modern browsers all support it β but providing a percentage fallback is good practice.
The meter Element
The <meter> element represents a scalar measurement within a known range β it is not a progress bar for tasks, but a gauge for a value that exists on a continuum. Think battery level, disk usage, password strength, or a score out of 100.
<!-- Disk usage: 70 GB of 100 GB used -->
<label for="disk">Disk usage: 70 GB of 100 GB</label>
<meter id="disk" value="70" min="0" max="100" low="80" high="90" optimum="10">
70 GB used
</meter>
<!-- Battery level: 45% -->
<label for="battery">Battery: 45%</label>
<meter id="battery" value="45" min="0" max="100" low="20" high="80" optimum="100">
45%
</meter>
<!-- Quiz score: 82 out of 100 -->
<label for="score">Your score: 82/100</label>
<meter id="score" value="82" min="0" max="100" low="50" high="75" optimum="100">
82 out of 100
</meter>
Key attributes on <meter>:
| Attribute | Meaning |
|---|---|
value | The current measurement (required) |
min | Minimum possible value (default 0) |
max | Maximum possible value (default 1) |
low | Upper boundary of the "low" range |
high | Lower boundary of the "high" range |
optimum | The ideal/best value β browser may colour the bar green when near optimum |
The dialog Element
The <dialog> element is a native modal dialog. It handles the overlay, focus trapping, and keyboard (Esc to close) behaviour that previously required significant JavaScript boilerplate or third-party libraries.
<!-- The dialog element (hidden by default) -->
<dialog id="confirm-dialog">
<h2>Confirm deletion</h2>
<p>Are you sure you want to delete this file? This cannot be undone.</p>
<div class="dialog-actions">
<button type="button" id="cancel-btn">Cancel</button>
<button type="button" id="delete-btn">Delete</button>
</div>
</dialog>
<!-- Trigger button -->
<button type="button" id="open-dialog">Delete file</button>
const dialog = document.getElementById('confirm-dialog');
const openBtn = document.getElementById('open-dialog');
const cancelBtn = document.getElementById('cancel-btn');
const deleteBtn = document.getElementById('delete-btn');
// showModal() opens as a modal with backdrop (focus trapped)
openBtn.addEventListener('click', () => dialog.showModal());
// close() closes the dialog
cancelBtn.addEventListener('click', () => dialog.close());
deleteBtn.addEventListener('click', () => {
// perform delete action
dialog.close();
});
dialog {
border: none;
border-radius: 8px;
padding: 2rem;
max-width: 400px;
width: 90vw;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}
/* Style the backdrop (only available for modal dialogs) */
dialog::backdrop {
background: rgba(0, 0, 0, 0.5);
}
dialog.showModal() opens the dialog as a modal with a backdrop and trapped keyboard focus β users cannot interact with content behind it. dialog.show() opens it as a non-modal (no backdrop, no focus trap). For confirmation dialogs and forms, always use showModal().
Brief Mention: Other HTML5 Elements
These elements each have their own dedicated pages on ylearner β they are listed here for completeness:
| Element | Purpose |
|---|---|
<video> | Embeds video with native browser controls, multiple sources, captions |
<audio> | Embeds audio with native browser controls and multiple fallback sources |
<canvas> | 2D/3D drawing surface; manipulated entirely via JavaScript Canvas API |
<template> | Client-side content template; inert until cloned and inserted by JavaScript |
<slot> | Placeholder inside Web Components for consumer-provided content |
<picture> | Responsive image with multiple source conditions (viewport size, format support) |
π Summary
<time datetime="">β makes dates and times machine-readable for search engines and calendar apps. Use ISO 8601 format indatetime.<mark>β highlights text relevant to the user's current context (search matches, key terms). Not the same as<em>or<strong>.<details>+<summary>β native collapsible accordion; no JavaScript needed. Add theopenattribute to default to expanded.<progress value="" max="">β task completion bar. Omitvaluefor an indeterminate/loading state.<meter value="" min="" max="" low="" high="" optimum="">β scalar gauge for a known range (battery, disk usage, score).<dialog>β native modal dialog; use.showModal()for focus-trapped modal behaviour and.close()to dismiss.
Frequently Asked Questions
What is the difference between progress and meter?
<progress> represents completion of a task β something moving toward an end state (a file download, a form wizard). <meter> represents a scalar value within a range that has no inherent "end" β it just measures where something currently stands (battery level, disk usage, a test score). If the reading changes over time but never "completes", use <meter>. If it tracks progress toward a defined goal, use <progress>.
Can I style details and summary completely?
Yes, with some caveats. The content area of <details> and the <summary> heading are fully styleable with CSS. The default triangle marker from <summary> can be removed with list-style: none (Firefox) and summary::-webkit-details-marker { display: none; } (Chrome/Safari). You can then add a custom indicator using ::before pseudo-elements with CSS transitions. The open/closed state can be targeted with details[open] in CSS.
Does the dialog element work in all browsers?
<dialog> is now supported in all major browsers (Chrome, Firefox, Safari, Edge) as of 2022. Firefox added support in version 98 (March 2022). For projects that must support very old browsers, the dialog-polyfill npm package is available. For new projects, native <dialog> is the preferred approach over DIY modal implementations.
Does the time element display differently from regular text?
No β <time> has no default visual styling. It renders as inline text, identical to the surrounding text. Its value is entirely semantic: the datetime attribute provides machine-readable data for search engines, scrapers, and browser extensions. You can style it with CSS if you want to visually distinguish dates (e.g., a slightly lighter colour or monospace font).