Divs and spans

If you’re used to the classic style of HTML, where you threw everything into tables and played with spacer GIFs until it all fell into more- or-less the layout you wanted, some of this will be new to you—so here’s a quick overview to bring you up to date.

XHTML contains two tags that are finally getting the attention they deserve: <div> and <span>. They’re used to break up your content into semantic chunks, that is, chunks that have a similar meaning. Things inside a single table cell or paragraph may or may not have anything in common, but the content within each <div> and <span> should.

Why use one over the other? A <div> is a block-level element, that is, there’s a physical break between it and the elements above and below ...

Get JavaScript and Ajax for the Web: Visual QuickStart Guide, Seventh Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.