Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>div</code> is a block element, <code>span</code> is inline.</p> <p>This means that to use them semantically, divs should be used to wrap sections of a document, while spans should be used to wrap small portions of text, images, etc.</p> <p>For example:</p> <pre><code>&lt;div&gt;This a large main division, with &lt;span&gt;a small bit&lt;/span&gt; of spanned text!&lt;/div&gt; </code></pre> <p>Note that it is illegal to place a block level element within an inline element, so:</p> <pre><code>&lt;div&gt;Some &lt;span&gt;text that &lt;div&gt;I want&lt;/div&gt; to mark&lt;/span&gt; up&lt;/div&gt; </code></pre> <p>...is illegal.</p> <hr> <p>EDIT: As of HTML5, some block elements can be placed inside of some inline elements. See the MDN reference <a href="https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories" rel="noreferrer">here</a> for a pretty clear listing. The above is still illegal, as <code>&lt;span&gt;</code> only accepts phrasing content, and <code>&lt;div&gt;</code> is flow content.</p> <hr> <p>You asked for some concrete examples, so is one taken from my bowling website, <a href="http://www.bowlsk.com" rel="noreferrer">BowlSK</a>:</p> <pre><code>&lt;div id="header"&gt; &lt;div id="userbar"&gt; Hi there, &lt;span class="username"&gt;Chris Marasti-Georg&lt;/span&gt; | &lt;a href="/edit-profile.html"&gt;Profile&lt;/a&gt; | &lt;a href="http://www.bowlsk.com/_ah/logout?..."&gt;Sign out&lt;/a&gt; &lt;/div&gt; &lt;h1&gt;&lt;a href="/"&gt;Bowl&lt;span class="sk"&gt;SK&lt;/span&gt;&lt;/a&gt;&lt;/h1&gt; &lt;/div&gt; </code></pre> <p>Ok, what's going on? At the top of my page, I have a logical section, the "header". Since this is a section, I use a div (with an appropriate id). Within that, I have a couple of sections: the user bar and the actual page title. The title uses the appropriate tag, <code>h1</code>. The userbar, being a section, is wrapped in a <code>div</code>. Within that, the username is wrapped in a <code>span</code>, so that I can change the style. As you can see, I have also wrapped a <code>span</code> around 2 letters in the title - this allows me to change their color in my stylesheet.</p> <p>Also note that HTML5 includes a broad new set of elements that define common page structures, such as article, section, nav, etc. Section 4.4 of the <a href="http://dev.w3.org/html5/spec/Overview.html" rel="noreferrer">HTML 5 working draft</a> lists them, and gives hints as to their usage. HTML5 is still a working spec, so nothing is "final" yet, but it is highly doubtful that any of these elements are going anywhere. There is a javascript hack that you will need to use if you want to style these elements in some older version of IE - you basically need to create one of each element using <code>document.createElement</code> before any of those elements are specified in your source. There are a bunch of libraries that will take care of this for you - a quick Google search turned up <a href="http://code.google.com/p/html5shiv/" rel="noreferrer">html5shiv</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload