English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

What is div and span tags in html?give difference between div and span tags?

2006-07-20 23:34:17 · 5 answers · asked by sharmi 1 in Computers & Internet Programming & Design

5 answers

The

tag defines logical divisions in your Web page. In terms of layout, the
tag does only one thing, it determines the alignment of that section of your page.

also gives you the chance to define the style of whole sections of HTML. You could define a section of your page as a call out and give that section a different style from the surrounding text.

But that's not all it does! The
tag gives you the ability to name certain sections of your documents so that you can affect them with style sheets or Dynamic HTML.

One thing to keep in mind when using the
tag is that it breaks paragraphs.
It acts as a paragraph end/beginning, and while you can have paragraphs within a
you can't have a
inside a paragraph.

The primary attributes of the
tag are:

* style
* class
* id

Even if you don't use style sheets or DHTML, you should get into the habit of using the
tag. This will give you more flexibility when more XML parsers become available. Also, you can use the id and name attributes to name your sections so that your Web pages are well formed (always use the name attribute with the id attribute and give them the same contents).

Because the
tag has been deprecated in HTML 4.0, it is a good idea to start using



to center the content inside your div.


Span Tag

The tag has very similar properties to the
tag, in that it affects the style of the text it encloses. Items in the can be aligned or given specific style attributes.

The primary difference between the and
tags is that doesn't do any formatting of it's own. The
tag acts as a paragraph break, because it is defining a logical division in the document. The tag simply tells the browser to apply the style and align rules to whatever is within the .

The tag has no required attributes, but the three that are the most useful are:

* style
* id
* class

Use when you want to change the style of elements without naming them in a separate division within the document. For example, if you had a Level 3 Heading (

) that you wanted the second word to be red, you could surround that word with

style="color : #f00;">2ndWord

and it would still be a part of the

tag as well

2006-07-20 23:55:24 · answer #1 · answered by Bharat Chauhan 2 · 2 0

The primary difference is that, by default,

tags are block elements (there are line breaks before and after the element) and span tags are inline elements (no default line breaks). This can be changed with the display: style, however.

2006-07-21 01:50:21 · answer #2 · answered by John J 6 · 1 0

span is used to set the display properties of a piece of text

div is a container for other elements (text, images, tables etc) it can have a with, and height, and can be set to be displayed at a certain position on the screen etc.

2006-07-20 23:44:00 · answer #3 · answered by Deep Thought 5 · 1 0

if you use new line after every tag it'll make the code more readable to a human. But it makes absolutely no difference for a browser.

2016-03-27 01:52:31 · answer #4 · answered by Anonymous · 1 0


it specifies the allignment of the enclosed element. can be use to divide a document into sections that r aligned differently.

2006-07-20 23:45:58 · answer #5 · answered by Anonymous · 1 0

this is a good website for you
http://www.w3schools.com

2006-07-20 23:39:13 · answer #6 · answered by currenz 2 · 1 0

fedest.com, questions and answers