HTML <section> Element

Publish in HTML Tutorial el 25/05/2025 16:06

HTML <section> Element: The Complete Guide

The <section> element is a semantic HTML tag used to define thematic groupings of content in a document. Unlike generic containers like <div>, <section> carries meaning about the structure of your content, helping search engines and assistive technologies understand your page organization.


Key characteristics of <section>:

  • Represents a standalone section of content
  • Should typically have a heading (h1-h6)
  • Used for grouping related content
  • Helps with document outline and accessibility


Basic Syntax

Here's the fundamental structure of a section element:


When to Use <section>

Use <section> for:

  • Chapter-like divisions of content
  • Tabbed content areas
  • Thematic groups in long articles
  • Distinct portions of a web application

Avoid using <section> as a generic container - for that purpose, <div> is more appropriate.


Practical Examples

Example 1: Basic Section with Content

This shows a simple section containing an article preview:

Play Code


Example 2: Multiple Sections in Article

Demonstrating how sections can divide a long article into logical parts:

Play Code


Example 3: Section with Styling

Showing how sections can be styled while maintaining semantic meaning:

Play Code


Example 4: Interactive Section with JavaScript

Demonstrating how sections can be manipulated with JavaScript:

Play Code


Example 5: Dynamic Section Loading

Showing how sections can be loaded dynamically via AJAX:

Play Code


Best Practices & Tips

  • Always include a heading: Each section should typically have a heading (h1-h6) to identify its purpose.
  • Don't use for styling only: If you need a container purely for styling, use <div> instead.
  • Nest sections logically: Sections can be nested to create a document outline.
  • Combine with ARIA: For complex sections, consider adding ARIA attributes for better accessibility.
  • Use for print styles: Sections make great targets for @media print rules.


Accessibility Considerations

When using <section> elements:

  • Ensure each section has an identifying heading
  • Consider adding aria-labelledby if headings aren't present
  • Use landmarks (role="region") for important sections when appropriate
  • Test with screen readers to ensure proper content grouping

By properly using <section> elements, you create more semantic, accessible, and maintainable HTML documents.

También te puede interesar

HTML <style> Element
HTML <style> Element

The <style> HTML element contains style information for a document, or part of a document. ...

HTML <strong> Element
HTML <strong> Element

The <strong> element is used to indicate that its content has strong importance, seriousnes...

HTML <span> Element
HTML <span> Element

The <span> element is an inline container used to mark up a part of a text or document. Unl...

HTML <source> Element
HTML <source> Element

The <source> element is used to specify multiple media resources for media elements like &l...

HTML <small> Element
HTML <small> Element

The <small> element is used to represent side-comments and small print, typically for discl...

HTML <script> Element
HTML <script> Element

The <script> HTML element is used to embed or reference executable code, typically JavaScri...