HTML 15 ๐Ÿ›๏ธ How to HTML main semantic element

โฑ๏ธ Estimated read: 7 min | |

1. How to Identify the Main Content Area

Steps:

  1. Look for the dominant content that’s unique to the page
  2. Check if it contains the primary information users came for
  3. Verify it’s not navigation, ads, or secondary elements
<main>
    <article>Primary article content</article>
    <section>Key information</section>
</main>

2. How to Add Class Attribute to Main Element

Steps:

  1. Open the <main> tag
  2. Add class="your-class-name"
  3. Apply CSS styles to that class
<main class="content-wrapper">
    <article>Article content</article>
</main>

3. How to Add ID Attribute to Main Element

Steps:

  1. Open the <main> tag
  2. Add id="unique-id-name"
  3. Use for direct linking or JavaScript targeting
<main id="primary-content">
    <article>Article content</article>
</main>

4. How to Add ARIA Role to Main Element

Steps:

  1. Open the <main> tag
  2. Add role="main"
  3. This helps screen readers understand content structure
<main role="main">
    <article>Article content</article>
</main>

5. How to Add ARIA Label to Main Element

Steps:

  1. Open the <main> tag
  2. Add aria-label="Descriptive text"
  3. Provides context for screen readers
<main aria-label="Main article content">
    <article>Article content</article>
</main>

6. How to Use Main with Article Elements

Steps:

  1. Place <article> inside <main>
  2. Each article should contain self-contained content
  3. Multiple articles allowed within main
<main>
    <article>First article</article>
    <article>Second article</article>
</main>

7. How to Use Main with Section Elements

Steps:

  1. Place <section> inside <main>
  2. Group related content together
  3. Sections can contain multiple elements
<main>
    <section>Introduction content</section>
    <section>Methodology details</section>
</main>

8. How to Structure Main Content Properly

Steps:

  1. Place <main> as direct child of <body>
  2. Ensure it’s the primary content area
  3. Avoid placing navigation or sidebars inside main
<body>
    <header>Header content</header>
    <main>Main content here</main>
    <footer>Footer content</footer>
</body>

9. How to Add Multiple Semantic Elements Inside Main

Steps:

  1. Include <article>, <section>, <aside> within main
  2. Maintain logical content organization
  3. Keep structure clear and accessible
<main>
    <article>Primary content</article>
    <section>Related information</section>
    <aside>Supplementary material</aside>
</main>

10. How to Use Main with Header and Footer

Steps:

  1. Place main between header and footer
  2. Ensure it’s the central content area
  3. Keep headers/footers separate from main content
<header>Navigation</header>
<main>Main article</main>
<footer>Copyright info</footer>

11. How to Style Main Element with CSS

Steps:

  1. Use main selector in CSS
  2. Apply layout and styling properties
  3. Ensure proper spacing and visual hierarchy
main {
    padding: 20px;
    max-width: 800px;
    margin: 0 auto;
}

12. How to Target Main Element with JavaScript

Steps:

  1. Use document.querySelector('main')
  2. Or document.getElementById('main-id')
  3. Manipulate content or properties
const mainContent = document.querySelector('main');
mainContent.style.backgroundColor = 'lightblue';

13. How to Create Responsive Main Content

Steps:

  1. Add max-width to main element
  2. Use relative units (em, %, vw)
  3. Ensure proper padding and margins
<main style="max-width: 900px; margin: 0 auto;">
    <article>Responsive content</article>
</main>

14. How to Add Accessible Main Element

Steps:

  1. Include role="main" attribute
  2. Add descriptive aria-label
  3. Ensure proper heading structure
<main role="main" aria-label="Article content">
    <h1>Article Title</h1>
    <p>Main content here</p>
</main>

15. How to Validate Single Main Element per Page

Steps:

  1. Check that only one <main> exists
  2. Verify it’s the primary content area
  3. Confirm no duplicate main elements
<!-- Correct: Only one main element -->
<body>
    <main>Primary content</main>
</body>

16. How to Use Main with Semantic Navigation

Steps:

  1. Place <nav> outside main section
  2. Keep navigation separate from main content
  3. Ensure clear separation of concerns
<header>
    <nav>Site navigation</nav>
</header>
<main>Main content here</main>

17. How to Add Proper Heading Structure in Main

Steps:

  1. Start with <h1> for main title
  2. Use proper heading hierarchy within main
  3. Ensure logical flow of information
<main>
    <h1>Main Article Title</h1>
    <h2>Section 1</h2>
    <h3>Subsection</h3>
</main>

18. How to Include Form Elements in Main

Steps:

  1. Place <form> inside <main>
  2. Ensure form is part of main content
  3. Add proper labeling for accessibility
<main>
    <form action="/submit" method="post">
        <input type="text" name="username">
    </form>
</main>

19. How to Use Main with Media Elements

Steps:

  1. Include images, videos, audio within main
  2. Ensure they’re part of primary content
  3. Add proper alt text for accessibility
<main>
    <img src="article.jpg" alt="Article illustration">
    <video controls>Video content</video>
</main>

20. How to Create Main with Interactive Elements

Steps:

  1. Add buttons, links, and interactive components
  2. Ensure they’re within main content area
  3. Maintain proper semantic relationships
<main>
    <button onclick="submitForm()">Submit</button>
    <a href="/more-info">Learn more</a>
</main>

21. How to Add Keyboard Navigation to Main Content

Steps:

  1. Ensure main content is focusable
  2. Test tab navigation through main elements
  3. Maintain logical tab order
<main tabindex="0">
    <article tabindex="0">Article content</article>
</main>

22. How to Add Focus Styles to Main Element

Steps:

  1. Use CSS :focus pseudo-class
  2. Apply visible focus indicators
  3. Ensure accessibility compliance
main:focus {
    outline: 2px solid blue;
    outline-offset: 2px;
}

23. How to Position Main Element in Layout

Steps:

  1. Use CSS positioning or flexbox
  2. Ensure main is the primary content area
  3. Maintain proper document flow
<div class="container">
    <main>Centered main content</main>
</div>

24. How to Add Background Styling to Main

Steps:

  1. Apply background properties to main
  2. Ensure readability of content
  3. Maintain contrast ratios
<main style="background-color: #f5f5f5; padding: 1rem;">
    <article>Content here</article>
</main>

25. How to Make Main Element Scrollable

Steps:

  1. Set overflow properties on main
  2. Ensure proper scrolling behavior
  3. Test on different devices
main {
    max-height: 500px;
    overflow-y: auto;
}

26. How to Add Margin and Padding to Main

Steps:

  1. Apply padding to main element
  2. Set margin for spacing
  3. Ensure consistent layout
<main style="padding: 20px; margin: 10px;">
    <article>Article content</article>
</main>

27. How to Add Border Styling to Main Element

Steps:

  1. Use CSS border properties
  2. Apply visually appealing borders
  3. Ensure they don’t interfere with content
<main style="border: 2px solid #ccc; padding: 15px;">
    <article>Article content</article>
</main>

28. How to Add Text Styling in Main Content

Steps:

  1. Apply typography to main content
  2. Use appropriate font sizes and weights
  3. Maintain readability standards
<main style="font-family: Arial, sans-serif; line-height: 1.6;">
    <article>Article text</article>
</main>

29. How to Add Flexbox Layout in Main

Steps:

  1. Use CSS flex properties on main
  2. Arrange child elements effectively
  3. Ensure responsive behavior
<main style="display: flex; flex-direction: column;">
    <article>First item</article>
    <section>Second item</section>
</main>

30. How to Add Grid Layout in Main

Steps:

  1. Use CSS grid properties on main
  2. Create structured content layouts
  3. Maintain semantic structure
<main style="display: grid; grid-template-columns: 1fr 1fr;">
    <article>Left content</article>
    <section>Right content</section>
</main>

Was this helpful?


Stop using slow, ad-bloated tool sites! ๐Ÿคฎ

๐Ÿ”Ž Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
โœ… Finance (Mortgage, Interest, Inflation)
โœ… Tech (Base64, JSON, Dev Suite, IP)
โœ… Health (BMI, BMR, TDEE)
โœ… Productivity (Timer, Workspace, QR)

โšก๏ธ Fast & Private
๐Ÿ”’ No data leaves your device
๐Ÿ’Ž 100% Free

๐Ÿ”— Use it now: https://tools.kandz.me
๐Ÿ”– Bookmark itโ€”youโ€™ll need it later!