File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes span and div Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "span and div" Watch "span and div" New topic

span and div

Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

What's the difference between span and div ? When do you use one rather than the other ?

[My Blog]
All roads lead to JavaRanch
Manio Manegra

Joined: Sep 15, 2006
Posts: 8
Hi Satou,
go for DIV when you want to pack a group of element in a single box you can apply style to.
For example put in a DIV all the elements you put in to create your menu. So you can apply styles for your menu by addressing all that style to the surrounding DIV tag.

Use SPAN tag when you want apply inline style. For example if you want to emphasize a phrase inside a wider text. You can count on SPAN to apply your style.

SPAN style does not create any discontinuity, for this very reason it's known as an inline element.
DIV style creates a discontinuity (it starts on a new line), this is why it is called a block element.

Jaikiran Pai

Joined: Jul 20, 2005
Posts: 10441

This article explains the difference:

Span and div difference

[My Blog] [JavaRanch Journal]
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

Very clear Thanks both of you.
I agree. Here's the link:
subject: span and div
It's not a secret anymore!