Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explain what a <div> tag is to a non-programmer [closed]

Tags:

html

markup

So my brother is home for the holidays, and he is trying to learn HTML & Javascript. I've had some success explaining to him many of the concepts related to this. Most of the tags are pretty self explanatory, but I've struggled with describing a div tag.

To be honest, I never really got a good description for myself, just through experience I know when to use one.

A good answer will not need to include the definition of "block element" or any other technical jargon, although you can assume some basic knowledge of some HTML tags

like image 480
Jameo Avatar asked Dec 25 '12 02:12

Jameo


People also ask

What does the div tag mean?

Definition and Usage The <div> tag defines a division or a section in an HTML document. The <div> tag is used as a container for HTML elements - which is then styled with CSS or manipulated with JavaScript. The <div> tag is easily styled by using the class or id attribute.

Does div tag need to be closed?

Div tag has both open(<div>) and closing (</div>) tag and it is mandatory to close the tag. The Div is the most usable tag in web development because it helps us to separate out data in the web page and we can create a particular section for particular data or function in the web pages.

What are div tags not used for?

The <div> tag is an empty container that is used to define a division or a section. It does not affect the content or layout and is used to group HTML elements to be styled with CSS or manipulated with scripts.


3 Answers

For some reason the purpose or logic around the <div> </div> tags, made sense to me looking at cloth clips, and the reason it is because:

  • Cloth clips are usually or almost always are applied Two for each type of cloth.(<div> </div>)
  • One can not work without the other, otherwise the cloth will fall. ex: <div> alone can not work.
  • The purpose of them is so that, they can hold a block of code ex: (a cloth in this case)
  • And control the structure, space, width, layout of a given object as per your desire.

enter image description here

like image 122
samayo Avatar answered Sep 28 '22 10:09

samayo


I think the W3's specs are quite approachable:

The div element has no special meaning at all. It represents its children. It can be used with the class, lang, and title attributes to mark up semantics common to a group of consecutive elements.

Note: Authors are strongly encouraged to view the div element as an element of last resort, for when no other element is suitable. Use of more appropriate elements instead of the div element leads to better accessibility for readers and easier maintainability for authors.

like image 20
steveax Avatar answered Sep 28 '22 11:09

steveax


The tag is nothing more than a container unit that encapsulates other page elements and divides the HTML document into sections. Web developers use elements to group together HTML elements and apply CSS styles to many elements at once. For instance, by wrapping a set of paragraph elements into a element, the developer can take advantage of CSS styles and apply a font to all paragraphs at once by applying a font style to the tag instead of coding the same style for each paragraph element.

Taken from http://www.tizag.com/htmlT/htmldiv.php

I think to be honest wikipedia proves a very simple explanation.

en.wikipedia.org/wiki/Div_tag

like image 28
Leo Correa Avatar answered Sep 28 '22 10:09

Leo Correa