Syntax
<div>
<!-- Content goes here -->
</div>Examples
Basic Container
Using a div as a simple container to group related content together.
<div>
<h2>Section Title</h2>
<p>This is some content inside a div container.</p>
<p>Divs help organize your page structure.</p>
</div>Styled Card Component
Creating a card layout using div with inline styles for visual presentation.
<div style="border: 1px solid #ddd; border-radius: 8px; padding: 20px; max-width: 400px;">
<h3 style="margin-top: 0;">Product Card</h3>
<p>This card demonstrates how divs can be styled to create visual components.</p>
<button style="background: #007bff; color: white; border: none; padding: 10px 20px; border-radius: 4px; cursor: pointer;">Learn More</button>
</div>Grid Layout
Using multiple divs to create a responsive grid layout for content organization.
<div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px;">
<div style="background: #f0f0f0; padding: 20px; border-radius: 8px;">
<h4>Column 1</h4>
<p>Content here</p>
</div>
<div style="background: #e0e0e0; padding: 20px; border-radius: 8px;">
<h4>Column 2</h4>
<p>Content here</p>
</div>
<div style="background: #d0d0d0; padding: 20px; border-radius: 8px;">
<h4>Column 3</h4>
<p>Content here</p>
</div>
</div>Nested Structure
Demonstrating how divs can be nested to create complex layouts and hierarchical structure.
<div style="background: #f5f5f5; padding: 20px;">
<div style="background: white; padding: 15px; margin-bottom: 10px; border-radius: 4px;">
<h3>Parent Container</h3>
<div style="background: #e8e8e8; padding: 10px; border-left: 3px solid #007bff;">
<p>Nested child div with custom styling</p>
</div>
</div>
</div>Attributes
- id (string): Unique identifier for the div element
- class (string): CSS class names for styling
- style (string): Inline CSS styles
- data-* (string): Custom data attributes for storing extra information
Best practices
- Use semantic HTML5 elements (section, article, nav) instead of divs when appropriate
- Add meaningful class or id names that describe the content, not the appearance
- Avoid excessive div nesting (div soup) - keep your structure as flat as possible
- Use divs for layout purposes and semantic elements for content structure
- Consider using CSS Grid or Flexbox on divs for modern, responsive layouts
- Don't use divs where a more specific element would be better (like <button> for buttons)
Browser compatibility
Support applies to the named feature, not every attribute or behaviour in this article. Versions refer to browsers, not operating systems.
<div>
Desktop
- Chrome
- Supported
From 1 - Firefox
- Supported
From 1 - Safari
- Supported
From 1 - Edge
- Supported
From 12 - Opera
- Supported
From 15
Mobile
- Safari on iOS
- Supported
From 1 - Chrome for Android
- Supported
From 18 - Firefox for Android
- Supported
From 4 - Samsung Internet
- Supported
From 1.0
MDN BCD record for this feature · MDN reference
Support history and limitations
Chrome
- From 1
Firefox
- From 1
Safari
- From 1
Edge
- From 12
Opera
- From 15
Safari on iOS
- From 1
Chrome for Android
- From 18
Firefox for Android
- From 4
Samsung Internet
- From 1.0
id
Desktop
- Chrome
- Supported
From 1 - Firefox
- Supported
From 32 - Safari
- Supported
From 1 - Edge
- Supported
From 12 - Opera
- Supported
From 15
Mobile
- Safari on iOS
- Supported
From 1 - Chrome for Android
- Supported
From 18 - Firefox for Android
- Supported
From 32 - Samsung Internet
- Supported
From 1.0
MDN BCD record for this feature · MDN reference
Support history and limitations
Chrome
- From 1
Firefox
- From 32
- From 1 · Removed in 32 · Last supported version: 31 · Partial implementation · id is a true global attribute only since Firefox 32.
Safari
- From 1
Edge
- From 12
Opera
- From 15
Safari on iOS
- From 1
Chrome for Android
- From 18
Firefox for Android
- From 32
- From 4 · Removed in 32 · Last supported version: 31 · Partial implementation · id is a true global attribute only since Firefox for Android 32.
Samsung Internet
- From 1.0
class
Desktop
- Chrome
- Supported
From 1 - Firefox
- Supported
From 1 - Safari
- Supported
By 4 (possibly earlier) - Edge
- Supported
From 12 - Opera
- Supported
From 15
Mobile
- Safari on iOS
- Supported
By 3.2 (possibly earlier) - Chrome for Android
- Supported
From 18 - Firefox for Android
- Supported
From 4 - Samsung Internet
- Supported
From 1.0
MDN BCD record for this feature · MDN reference
Support history and limitations
Chrome
- From 1
Firefox
- From 1
Safari
- By 4 (possibly earlier)
Edge
- From 12
Opera
- From 15
Safari on iOS
- By 3.2 (possibly earlier)
Chrome for Android
- From 18
Firefox for Android
- From 4
Samsung Internet
- From 1.0
style
Desktop
- Chrome
- Supported
From 1 - Firefox
- Supported
From 1 - Safari
- Supported
From 1 - Edge
- Supported
From 12 - Opera
- Supported
From 15
Mobile
- Safari on iOS
- Supported
From 1 - Chrome for Android
- Supported
From 18 - Firefox for Android
- Supported
From 4 - Samsung Internet
- Supported
From 1.0
MDN BCD record for this feature · MDN reference
Support history and limitations
Chrome
- From 1
Firefox
- From 1
Safari
- From 1
Edge
- From 12
Opera
- From 15
Safari on iOS
- From 1
Chrome for Android
- From 18
Firefox for Android
- From 4
Samsung Internet
- From 1.0
data attributes
Desktop
- Chrome
- Supported
From 7 - Firefox
- Supported
From 6 - Safari
- Supported
From 5.1 - Edge
- Supported
From 12 - Opera
- Supported
From 15
Mobile
- Safari on iOS
- Supported
From 5 - Chrome for Android
- Supported
From 18 - Firefox for Android
- Supported
From 6 - Samsung Internet
- Supported
From 1.0
MDN BCD record for this feature · MDN reference
Support history and limitations
Chrome
- From 7
Firefox
- From 6
Safari
- From 5.1
Edge
- From 12
Opera
- From 15
Safari on iOS
- From 5
Chrome for Android
- From 18
Firefox for Android
- From 6
Samsung Internet
- From 1.0
MDN BCD 8.1.5 · Dataset built 2026-10-08 · Mapping reviewed 2026-10-21. These dates are not individual browser-test or claim-verification dates. Unknown means the data does not establish support.