HTML Tag Reference

HTML Living Standard

Look up common tags, run a short example, and check a frequent mistake.

On this page

<a href="…">

Wrap link text in <a> and put the destination in href. A fragment such as #hours jumps to a matching id in the same page.

How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>&lt;a href="…"&gt;</title>
</head>
<body>
<a href="#hours">See opening hours</a>
<h2 id="hours">Opening hours</h2>
</body>
</html>

What to expect Select See opening hours to move focus to its heading.

Common mistake The target id must match the part after # exactly.

<img src="…" alt="…">

Use src for the image and alt for a text replacement when the image conveys information. img has no closing tag.

How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>&lt;img src="…" alt="…"&gt;</title>
</head>
<body>
<img width="120" height="48" alt="Store logo"
  src="data:image/svg+xml,%3Csvg%20xmlns=%27http://www.w3.org/2000/svg%27%20viewBox=%270%200%20120%2048%27%3E%3Crect%20width=%27120%27%20height=%2748%27%20fill=%27teal%27/%3E%3Ctext%20x=%2742%27%20y=%2730%27%20fill=%27white%27%3EShop%3C/text%3E%3C/svg%3E">
</body>
</html>

What to expect The embedded icon displays. Clear src to see how its alternative text is used.

Common mistake Use an empty alt="" for a decorative image whose information is already available nearby.

<label> and <input>

Match label for to input id so they work together. Use name to identify the value when the form is submitted.

How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>&lt;label&gt; and &lt;input&gt;</title>
</head>
<body>
<label for="customer">Customer name</label>
<input id="customer" name="customer" type="text">
</body>
</html>

What to expect Click Customer name to focus the input and type a name.

Common mistake Match for to id. The name attribute has a separate purpose.

<button type="…">

Use a button for an action. A button in a form defaults to submitting. Set type="button" for a separate action.

How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>&lt;button type="…"&gt;</title>
</head>
<body>
<form>
  <label for="order-note">Note</label>
  <input id="order-note" value="Less sugar">
  <button type="button" id="clear">Clear</button>
</form>
  <script>
document.querySelector("#clear").addEventListener("click", () => {
  document.querySelector("#order-note").value = "";
});
  </script>
</body>
</html>

What to expect Click Clear to empty the field and stay in the form.

Common mistake Give button an explicit type in a form to avoid an accidental submit.

Final project: a three-page website

Build Home, Services and Contact pages linked by shared navigation. Give each a unique title and description. Add an accessible pricing table and labelled contact form. Navigate using Tab and Enter, try the skip link, and validate each complete document at validator.w3.org. Fix errors and retest all three pages.

Official references