HTML <div> Element

The <div> element is a generic container used to group related HTML content. It does not describe the meaning of the content by itself, but it is useful for organizing page structure and applying shared CSS styles, layouts, or other behavior to a group of elements.

Syntax

<div>
  <h2>Section Heading</h2>
  <p>Content grouped inside the div element.</p>
</div>

The <div> element uses an opening and closing tag and can contain headings, paragraphs, images, links, lists, and many other HTML elements.

Attributes

The <div> element supports the global HTML attributes. It does not have any element-specific attributes.

Example

The following example groups related content inside a <div> and uses a class to apply CSS styling to the entire container:

Play in Editor

Usage Notes

The <div> element has no specific semantic meaning. It is primarily used when content needs to be grouped and there is no more appropriate semantic HTML element for that group.

Classes and IDs are commonly assigned to <div> elements so CSS can control their layout, spacing, colors, borders, and other presentation.

Before using a <div>, consider whether an element such as <header>, <nav>, <main>, <section>, <article>, <aside>, or <footer> better describes the purpose of the content.

Using semantic elements where appropriate makes the document structure easier for browsers, assistive technologies, search engines, and developers to understand.

Accessibility

A <div> does not provide a meaningful semantic role by itself, so do not rely on it when a native HTML element already represents the purpose or behavior of the content.

Do not make a <div> behave like a button, link, or other interactive control solely through styling and scripting when the corresponding native HTML element can be used instead. Native interactive elements provide important keyboard and accessibility behavior automatically.

Browser Support

Baseline: Widely available indicates a feature has been supported by core browsers for at least 30 months. At this stage, the feature is considered stable and safe for most websites to use without needing to worry about compatibility issues or fallbacks, as it is supported by the vast majority of users' devices and browser versions.

For detailed browser compatibility information, see Can I Use: HTML <div> Element .

<span> - Provides a generic inline container for grouping text or other phrasing content.

<section> - Represents a thematic section of a document and provides more semantic meaning than a generic container.

<article> - Represents self-contained content that can stand independently.

<main> - Represents the primary content of a document.

Specifications

HTML Living Standard: The <div> Element