# Edits & Computer Text

> Six elements handle document edits and computer-related text spans. The first two track what changed; the other four label what kind of machine text you are looking at.

Subject: HTML | Lesson 12 of 42 | 5 min read
Interactive lesson: https://codewithanimation.in/html/edits-and-computer-text
Previous: [mark, small, sub & sup](https://codewithanimation.in/html/mark-small-sub-sup.md) | Next: [abbr, q, time & span](https://codewithanimation.in/html/abbr-q-time-and-span.md)

## What they are

`<del>` marks text that has been removed from a document. The browser renders it with a strikethrough by default. `<ins>` marks text that has been added. Both accept a `cite` attribute (a URL explaining the change) and a `datetime` attribute (an ISO 8601 timestamp), giving machines a way to understand what changed and when.

`<code>` wraps a fragment of code: a function name, a variable, a file path, or any string that the reader should understand as computer syntax. `<kbd>` marks text the user types on a keyboard, a key name like Escape or a combo like Ctrl+S. `<samp>` marks sample output from a program, and `<var>` marks a variable in a mathematical expression or code context.

## Why it matters

`<del>` and `<ins>` carry meaning that a plain CSS strikethrough cannot. A stylesheet change is invisible to search engines, screen readers, and anything parsing the document structure. When a price drops from $99 to $79 and you mark the old price with `<del>`, the change is part of the document record. The `datetime` attribute goes further: it gives the exact moment of the edit in a machine-readable form.

`<code>` and `<kbd>` are the visible face of code in prose. A technical blog post that wraps command names in `<code>` and keyboard shortcuts in `<kbd>` gives copy-paste tools, screen readers, and syntax highlighters the right hook. They also signal to the reader: this is something to type or run, not just a word.

## How it works

Wrap deleted content in `<del>` and inserted content in `<ins>`. Both can wrap inline text or whole block elements like paragraphs. A price correction `<del>$99</del> <ins>$79</ins>` is the canonical inline example; a tracked-changes document might wrap entire `<p>` blocks. Add `cite` and `datetime` when the context warrants it, though they are optional.

Use `<code>` for any string that is code: a function name in prose, a file path, a shell command embedded in a sentence. For a multi-line block, the convention is `<pre><code>...</code></pre>`: the `<pre>` preserves whitespace and the `<code>` provides the semantic label.

Use `<kbd>` for keyboard input the user gives: key names (Enter, Escape), combinations (Ctrl+S), or typed commands. Use `<samp>` for text the computer outputs, such as an error message or terminal response. Use `<var>` for a variable: `the value of <var>n</var>`. All four render in monospace by default and can be styled further with CSS.

## Common mistake: Using <code> for non-code monospace text

It is tempting to wrap any text you want in a monospace font inside `<code>`. That gives the visual result you want but misrepresents the content as code. If the text is a brand name, a product identifier, or a label that happens to look better in mono, use a `<span>` with `font-family: monospace`. Save `<code>` for content that is genuinely computer syntax.

## Tip: <kbd> is input, <samp> is output

The two most confused computer-text elements: `<kbd>` marks what you type or press (keyboard input), and `<samp>` marks what the computer shows back (program output). A tutorial that says to run a command and shows the result should use `<kbd>` for the command you type and `<samp>` for the response the terminal prints. Swapping them is a quiet semantic error that does not break rendering but mislabels the communication direction.

## Try it: Try it

See `<del>` and `<ins>` mark a price change, `<code>` wrap a command in prose, and `<kbd>` render a keyboard shortcut.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/html/edits-and-computer-text

## Check yourself

### Question 1

A product page shows the original price crossed out and the new price next to it. Which markup is correct?

- A. <del>$99</del> <ins>$79</ins>
- B. <s>$99</s> $79
- C. <strike>$99</strike> $79

Correct answer: A

`<del>` and `<ins>` document editorial changes: what was removed and what replaced it. A price correction is exactly this use case. `<s>` would only produce a visual strikethrough with no semantic meaning.

- Why not B: <s> renders a strikethrough but carries no editorial meaning. <del> signals that this text was removed from the document record, which is semantically correct for a price change.
- Why not C: <strike> is obsolete. Use <del> for editorial deletions and CSS text-decoration for purely visual strikethrough.

### Question 2

A tutorial says: "Type npm start and the terminal prints: Server running on port 3000." How do you mark those two spans?

- A. <kbd>npm start</kbd> and <samp>Server running on port 3000</samp>
- B. <samp>npm start</samp> and <kbd>Server running on port 3000</kbd>
- C. <code>npm start</code> and <code>Server running on port 3000</code>

Correct answer: A

`<kbd>` marks text the user types; `<samp>` marks text the computer outputs. Getting this right labels the direction of communication correctly for screen readers and documentation tools.

- Why not B: <samp> is program output, <kbd> is user input. The command the user types is <kbd>; the terminal response is <samp>.
- Why not C: <code> is for code fragments. The command is keyboard input (<kbd>) and the response is sample output (<samp>). Both are more specific than <code> here.

### Question 3

You want a product SKU to appear in a monospace font. Which is correct?

- A. <span style="font-family: monospace">SKU-4821</span>
- B. <code>SKU-4821</code>
- C. <kbd>SKU-4821</kbd>

Correct answer: A

Reserve `<code>` for actual code content. When you only want monospace styling with no semantic meaning, apply `font-family: monospace` via CSS to a neutral `<span>`.

- Why not B: A product SKU is not computer code. <code> would misrepresent it as a code fragment. Use CSS on a <span> when you only want the visual style.
- Why not C: <kbd> is for text the user types on a keyboard. A product SKU is neither keyboard input nor computer code.

## Remember this

- `<del>` marks removed text (strikethrough); `<ins>` marks added text (underline); both support `cite` and `datetime`.
- `<code>` is for code fragments; `<kbd>` is for keyboard input the user types; `<samp>` is for program output.
- For multi-line code blocks, use `<pre><code>...</code></pre>`: `<pre>` preserves whitespace, `<code>` labels it as code.
- Do not use `<code>` purely for monospace styling; use a `<span>` with CSS `font-family: monospace` instead.
