HTML 15 ๐๏ธ How to HTML main semantic element
1. How to Identify the Main Content Area
Steps:
- Look for the dominant content that’s unique to the page
- Check if it contains the primary information users came for
- 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:
- Open the
<main>tag - Add
class="your-class-name" - 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:
- Open the
<main>tag - Add
id="unique-id-name" - 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:
- Open the
<main>tag - Add
role="main" - 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:
- Open the
<main>tag - Add
aria-label="Descriptive text" - 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:
- Place
<article>inside<main> - Each article should contain self-contained content
- Multiple articles allowed within main
<main>
<article>First article</article>
<article>Second article</article>
</main>
7. How to Use Main with Section Elements
Steps:
- Place
<section>inside<main> - Group related content together
- Sections can contain multiple elements
<main>
<section>Introduction content</section>
<section>Methodology details</section>
</main>
8. How to Structure Main Content Properly
Steps:
- Place
<main>as direct child of<body> - Ensure it’s the primary content area
- 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:
- Include
<article>,<section>,<aside>within main - Maintain logical content organization
- 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:
- Place main between header and footer
- Ensure it’s the central content area
- 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:
- Use
mainselector in CSS - Apply layout and styling properties
- Ensure proper spacing and visual hierarchy
main {
padding: 20px;
max-width: 800px;
margin: 0 auto;
}
12. How to Target Main Element with JavaScript
Steps:
- Use
document.querySelector('main') - Or
document.getElementById('main-id') - Manipulate content or properties
const mainContent = document.querySelector('main');
mainContent.style.backgroundColor = 'lightblue';
13. How to Create Responsive Main Content
Steps:
- Add
max-widthto main element - Use relative units (em, %, vw)
- 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:
- Include
role="main"attribute - Add descriptive
aria-label - 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:
- Check that only one
<main>exists - Verify it’s the primary content area
- 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:
- Place
<nav>outside main section - Keep navigation separate from main content
- 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:
- Start with
<h1>for main title - Use proper heading hierarchy within main
- 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:
- Place
<form>inside<main> - Ensure form is part of main content
- 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:
- Include images, videos, audio within main
- Ensure they’re part of primary content
- 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:
- Add buttons, links, and interactive components
- Ensure they’re within main content area
- 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:
- Ensure main content is focusable
- Test tab navigation through main elements
- Maintain logical tab order
<main tabindex="0">
<article tabindex="0">Article content</article>
</main>
22. How to Add Focus Styles to Main Element
Steps:
- Use CSS
:focuspseudo-class - Apply visible focus indicators
- Ensure accessibility compliance
main:focus {
outline: 2px solid blue;
outline-offset: 2px;
}
23. How to Position Main Element in Layout
Steps:
- Use CSS positioning or flexbox
- Ensure main is the primary content area
- Maintain proper document flow
<div class="container">
<main>Centered main content</main>
</div>
24. How to Add Background Styling to Main
Steps:
- Apply background properties to main
- Ensure readability of content
- Maintain contrast ratios
<main style="background-color: #f5f5f5; padding: 1rem;">
<article>Content here</article>
</main>
25. How to Make Main Element Scrollable
Steps:
- Set overflow properties on main
- Ensure proper scrolling behavior
- Test on different devices
main {
max-height: 500px;
overflow-y: auto;
}
26. How to Add Margin and Padding to Main
Steps:
- Apply padding to main element
- Set margin for spacing
- Ensure consistent layout
<main style="padding: 20px; margin: 10px;">
<article>Article content</article>
</main>
27. How to Add Border Styling to Main Element
Steps:
- Use CSS border properties
- Apply visually appealing borders
- 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:
- Apply typography to main content
- Use appropriate font sizes and weights
- 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:
- Use CSS flex properties on main
- Arrange child elements effectively
- 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:
- Use CSS grid properties on main
- Create structured content layouts
- Maintain semantic structure
<main style="display: grid; grid-template-columns: 1fr 1fr;">
<article>Left content</article>
<section>Right content</section>
</main>
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!