<p>I would like to ask for some simple examples showing the uses of <code>&lt;div&gt;</code> and <code>&lt;span&gt;</code>. I've seen them both used to mark a section of a page with an <code>id</code> or <code>class</code>, but I'm interested in knowing if there are times when one is preferred over the other.</p>

```
<div>
```
is a block-level element and
```
<span>
```
is an inline element.
If you wanted to do something with some inline text,
```
<span>
```
is the way to go since it will not introduce line breaks that a
```
<div>
```
would.
As noted by others, there are some semantics implied with each of these, most significantly the fact that a
```
<div>
```
implies a logical division in the document, akin to maybe a section of a document or something, a la:
```
```
<div id="Chapter1">
   <p>Lorem ipsum dolor sit amet, <span id="SomeSpecialText1">consectetuer adipiscing</span> elit. Duis congue vehicula purus.</p>
   <p>Nam <span id="SomeSpecialText2">eget magna nec</span> sapien fringilla euismod. Donec hendrerit.</p> 
</div>
```
```