Site icon David Yin's Blog

DIV and SPAN

Within standard design web site, the DIV and SPAN are used widely.
The W3C, in “The Global Structure of an HTML Document,” defines these two elements.
The DIV and SPAN elements, in conjunction with the id and class attributes, offer a generic mechanism for adding structure to documents. These elements define content to be inline (SPAN) or block-level (DIV) but impose no other presentational idioms on the content. Thus, authors may use these elements in conjunction with style sheets, the lang attribute, etc., to tailor HTML to their own needs and tastes.
What is This Thing Called div?
This is as good a place as any to explain that “div” is short for “division.”
When you group a bunch of links together, that’s one division of a document. Content would be another, the legal disclaimer at the foot of the page would be still another, and so on.


The id attribute has several roles in HTML:
As a style sheet selector.
As a target anchor for hypertext links.
As a means to reference a particular element from a script.
As the name of a declared OBJECT element.
For general purpose processing by user agents (e.g. for identifying fields when extracting data from HTML pages into a database, translating HTML documents into other formats, etc.).
The class attribute, on the other hand, assigns one or more class names to an element; the element may be said to belong to these classes. A class name may be shared by several element instances. The class attribute has several roles in HTML:
As a style sheet selector (when an author wishes to assign style information to a set of elements).
For general purpose processing by user agents.
Reference: W3C The global structure of an HTML document

Exit mobile version