If you're using Breakdance builder and want to improve your site's semantic HTML structure, you might have noticed that wrapping your main content in a <main> tag isn't straightforward. Here's a simple JavaScript solution that automatically wraps your designated sections in a proper <main> element.
With Breakdance builder you can only designate one section with the <main> tag. But what if you want multiple sections within <main>? Breakdance builder doesn't provide a native way to wrap multiple sections in a <main> tag. This is important for accessibility and SEO, as the <main> element helps screen readers and search engines identify the primary content of your page.
This lightweight JavaScript snippet allows you to mark your first and last sections with custom attributes, and it automatically wraps everything in between with a <main> tag.
The code is simple and efficient:
document.addEventListener('DOMContentLoaded', function() {
 const first = document.querySelector('[firstsection]');
 const last = document.querySelector('[lastsection]');
 if (first && last) {
   // Create the <main> element
   const main = document.createElement('main');
   // Insert <main> before the first section
   first.parentNode.insertBefore(main, first);
   // Move all elements between first and last (inclusive) into <main>
   let el = first;
   while (el) {
     const next = el.nextElementSibling;
     main.appendChild(el);
     if (el === last) break;
     el = next;
   }
 }
});


This simple solution bridges the gap in Breakdance builder's semantic HTML capabilities. By adding just a few lines of JavaScript and two custom attributes, you can ensure your site follows best practices for accessibility and SEO.