Grouping Content with <div> and <span>

HTML Living Standard

Generic containers group content when a more specific element does not describe its purpose.

On this page

Group elements with <div>

A div groups elements so CSS or JavaScript can work with them together. By default it creates a block box, so it starts on a new line. It adds no special meaning to the group.

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>Group elements with &lt;div&gt;</title>
  <style>
.card { border: 2px solid teal; padding: 12px; }
  </style>
</head>
<body>
<div class="card">
  <h2>Desk Lamp</h2>
  <p>2,500 MMK</p>
</div>
<p>Orders close at 5 PM.</p>
</body>
</html>

What to expect The name and price sit inside one bordered card.

Mark part of a line with <span>

A span wraps part of a line without starting a new block. Give it a class when you need to style only that part. For emphasis that has meaning, use a suitable element such as <strong>.

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>Mark part of a line with &lt;span&gt;</title>
  <style>
.price { color: teal; font-weight: bold; }
  </style>
</head>
<body>
<p>Desk Lamp: <span class="price">2,500 MMK</span> per item.</p>
</body>
</html>

What to expect Only the price turns teal and stays on the same line.

Official references