ArticleslgStudy

science

Div and span

Div and span is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Div and span rather than just read about it. In short: In HTML, the standard markup language for documents designed to be displayed in a web browser, <div> and <span> tags are elements used to define parts of a document, so that they are identifiable when a unique classification is necessary. Where other HTML elements such as <p> (paragraph), <em> (emphasis), and so on, accurately represent the semantics of the content, the additional use of <span> and <div> tags leads…

Key takeaways

  • Div and span belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Div and span to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Div and span from memory before moving on to harder problems.

Reference excerpt

In HTML, the standard markup language for documents designed to be displayed in a web browser, <div> and <span> tags are elements used to define parts of a document, so that they are identifiable when a unique classification is necessary. Where other HTML elements such as <p> (paragraph), <em> (emphasis), and so on, accurately represent the semantics of the content, the additional use of <span> and <div> tags leads to better accessibility for readers and easier maintainability for authors. Where no existing HTML element is applicable, <div> and <span> can valuably represent parts of a document so that HTML attributes such as class, id, lang, or dir can be applied. <span> represents an inline portion of a document, for example words within a sentence. <div> stands for "division", and represents a block-level portion of a document such as a few paragraphs or an image with its caption. The elements allow semantic attributes (e.g. lang="en-US"), CSS styling (e.g., color and typography), and client-side scripting (e.g., animation, hiding, and augmentation) to be applied.

Examples For example, to make a certain part of text inside a paragraph red, <span> can be used as follows:

History The <span> element was introduced to HTML in the internationalization working group's second draft html-i18n in 1995. However, it was not until HTML 4.01 that it became part of the HTML language, appearing in the HTML 4 W3C Working Draft in 1997. <span> was introduced to mark up any inline span of text, because "a generic container is needed to carry the LANG and BIDI attributes in cases where no other element is appropriate." It still serves that general purpose, although a much richer range of semantic elements have been defined since then, and there are also many more attributes that may need to be applied.

Differences and default behaviour There are multiple differences between <div> and <span>. The most notable difference is how the elements are displayed. In standard HTML, a <div> is a block-level element whereas a <span> is an inline element. The <div> block visually isolates a section of a document on the page, and may contain other block-level components. The <span> element contains a piece of information inline with the surrounding content, and may only contain other inline-level components. In practice, the default display of the elements can be changed by the use of Cascading Style Sheets (CSS), although the permitted contents of each element may not be changed. For example, regardless of CSS, a <span> element may not contain block-level children.

Practical use <span> and <div> elements are used purely to imply a logical grouping of enclosed elements. There are three main reasons to use <span> and <div> tags with class or id attributes:

Styling with CSS

It is common for <span> and <div> elements to carry class or id attributes in conjunction with CSS to apply layout, typographic, color, and other presentation attributes to parts of the content. CSS does not just apply to visual styling: when spoken out loud by a voice browser, CSS styling can affect speech-rate, stress, richness and even position within a stereophonic image. For these reasons, and in support of a more semantic web, attributes attached to elements within HTML should describe their semantic purpose, rather than merely their intended display properties in one particular medium. For example, the HTML in <span class="red-bold">password too short</span> is semantically weak, whereas <em class="warning">password too short</em> uses an <em> element to signify emphasis (appearing as text in italics), and introduces a more appropriate class name. By the correct use of CSS, such "warnings" may be rendered in a red, bold font on a screen, but when printed out they may be omitted, as by then it is too late to do anything about them. Perhaps when spoken they should be given extra stress, and a small reduction in speech-rate. The second example is semantically richer markup, rather than merely presentational.

Semantic clarity This grouping and labelling of parts of the page content might be introduced to make the page more semantically meaningful in general terms. For some years, the World Wide Web Consortium (W3C) has been running a major Semantic Web project designed to make the whole web increasingly useful and meaningful to today's and the future's information systems. The microformats movement is an attempt to build an idea of semantic classes. For example, microformats-aware software might automatically find an element like <span class="tel">123-456-7890</span> and allow for automatic dialing of the telephone number.

Access from code Once the HTML or XHTML markup is delivered to a page-visitor's client browser, there is a chance that client-side code will need to navigate the internal structure (or Document Object Model) of the web page. The most common reason for this is that the page is delivered with client-side JavaScript that will produce on-going dynamic behaviour after the page is rendered. For example, if rolling the mouse over a "Buy now" link is meant to make the price, elsewhere on the page, become emphasized, JavaScript code can do this, but JavaScript needs to identify the price element, wherever it is in the markup. The following markup would suffice: <div class="price">$45.99</div>. Another example is the Ajax programming technique, where, for example, clicking a hypertext link may cause JavaScript code to retrieve the text for a new price quotation to display in place of the current one within the page, without re-loading the whole page. When the new text arrives back from the server, the JavaScript must identify the exact region on the page to replace with the new information. Automatic testing tools also may need to navigate web page markup using <span> and <div> elements' class or id attributes. In dynamically generated HTML, this may include the use of page testing tools such as HttpUnit, a member of the xUnit family, and load or stress testing tools such as Apache JMeter when applied to form-driven web sites.

Overuse The judicious use of <div> and <span> is a vital part of HTML and XHTML markup. However, they are sometimes overused. Various list structures available in HTML may be preferable to a home-made mixture of <div> and <span> elements. For example, this:

which produces

Main page Contents Help

... is usually preferable instead of this:

which produces

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Div and span

Start with the simplest possible case. Write down what Div and span claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Div and span before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Div and span ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Div and span

In research
Div and span appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Div and span in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Div and span is common in secondary-school and first-year university syllabi. It links to neighbouring topics HTML, HTML tags, so understanding it makes those chapters shorter.
In everyday life
Look for Div and span outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Div and span” →

How to study Div and span in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Div and span means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Div and span out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Div and span in simple terms?

In HTML, the standard markup language for documents designed to be displayed in a web browser, <div> and <span> tags are elements used to define parts of a document, so that they are identifiable when a unique classification is necessary. Where other HTML elements such as <p> (paragraph), <em> (emp…

Why does Div and span matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Div and span?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Div and span.

Tags

  • HTML
  • HTML tags

Keep exploring