HTML Element: div

The div element has no special meaning, but it’s used a lot! In short, it represents its children. It is used to group elements on a page for styling contexts.

It’s an easy choice, but you should really use the <div> element as last resort for the sake of accessibility. For example, instead of using a <div> element to group the content from a long form article you could reach for the <article> element instead.

Example

Syntax

1
<div class="container">
2
  <article>
3
    <p>Ipsum labore velit anim nulla aliqua ea in mollit et eiusmod minim aute do. Cillum elit do veniam deserunt aliqua enim consequat nisi laboris fugiat sint. Ad enim enim non.</p>
4
  </article>
5
  <article>
6
    <p>Ipsum labore velit anim nulla aliqua ea in mollit et eiusmod minim aute do. Cillum elit do veniam deserunt aliqua enim consequat nisi laboris fugiat sint. Ad enim enim non.</p>
7
  </article>
8
</div>

Result

Browser Support

The <div> tag is supported in all modern browsers. Read more on caniuse.com.

Attributes

The <div> tag supports Global Attributes in HTML. Global Attributes are common to all HTML elements and can be used on all of them (though they may not have much of an effect on some of them).

Content

If the <div> element is not a child of a <dl> element the type of content model is flow content. If it is a child of the <dl> element it is used for wrapping groups of dt and dd elements.

Related HTML Elements

  • The <div> element is similar to the <span> element, in that they’re both generic and don’t describe their content. However, <span> is an inline element.

Learn More

Inspiring! Lynn Fisher’s a.singlediv.com is a project showing just how much a single <div> can be styled by CSS.


This content originally appeared on Envato Tuts+ Tutorials and was authored by Andy Leverenz

The div element has no special meaning, but it’s used a lot! In short, it represents its children. It is used to group elements on a page for styling contexts.

It’s an easy choice, but you should really use the <div> element as last resort for the sake of accessibility. For example, instead of using a <div> element to group the content from a long form article you could reach for the <article> element instead.

Example

Syntax

1
<div class="container">
2
  <article>
3
    <p>Ipsum labore velit anim nulla aliqua ea in mollit et eiusmod minim aute do. Cillum elit do veniam deserunt aliqua enim consequat nisi laboris fugiat sint. Ad enim enim non.</p>
4
  </article>
5
  <article>
6
    <p>Ipsum labore velit anim nulla aliqua ea in mollit et eiusmod minim aute do. Cillum elit do veniam deserunt aliqua enim consequat nisi laboris fugiat sint. Ad enim enim non.</p>
7
  </article>
8
</div>

Result

Browser Support

The <div> tag is supported in all modern browsers. Read more on caniuse.com.

Attributes

The <div> tag supports Global Attributes in HTML. Global Attributes are common to all HTML elements and can be used on all of them (though they may not have much of an effect on some of them).

Content

If the <div> element is not a child of a <dl> element the type of content model is flow content. If it is a child of the <dl> element it is used for wrapping groups of dt and dd elements.

  • The <div> element is similar to the <span> element, in that they’re both generic and don’t describe their content. However, <span> is an inline element.

Learn More

Inspiring! Lynn Fisher’s a.singlediv.com is a project showing just how much a single <div> can be styled by CSS.


This content originally appeared on Envato Tuts+ Tutorials and was authored by Andy Leverenz


Print Share Comment Cite Upload Translate Updates
APA

Andy Leverenz | Sciencx (2023-02-10T13:34:00+00:00) HTML Element: div. Retrieved from https://www.scien.cx/2023/02/10/html-element-div/

MLA
" » HTML Element: div." Andy Leverenz | Sciencx - Friday February 10, 2023, https://www.scien.cx/2023/02/10/html-element-div/
HARVARD
Andy Leverenz | Sciencx Friday February 10, 2023 » HTML Element: div., viewed ,<https://www.scien.cx/2023/02/10/html-element-div/>
VANCOUVER
Andy Leverenz | Sciencx - » HTML Element: div. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/02/10/html-element-div/
CHICAGO
" » HTML Element: div." Andy Leverenz | Sciencx - Accessed . https://www.scien.cx/2023/02/10/html-element-div/
IEEE
" » HTML Element: div." Andy Leverenz | Sciencx [Online]. Available: https://www.scien.cx/2023/02/10/html-element-div/. [Accessed: ]
rf:citation
» HTML Element: div | Andy Leverenz | Sciencx | https://www.scien.cx/2023/02/10/html-element-div/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.