How To Create Browser-Native Toggles Using Divi 5’s Semantic Tags

by | Feb 24, 2026 | Etcetera | 0 comments

Accordions and toggle content material have historically required JavaScript to deal with the interplay accurately. Trendy HTML comprises local parts that get you nearer to a non-JavaScript model of that.

<particulars> and <abstract> parts create purposeful disclosure widgets the use of not anything however a few easy parts. Those parts deal with enlarge/cave in habits routinely, beef up keyboard interplay out of the field, and paintings with none additional JavaScript.

Divi 5’s Semantic Elements permit customers to paintings with those local HTML parts (and lots of others) immediately inside the Visual Builder. You’ll be able to assemble toggles the use of Divi’s structure parts whilst outputting blank, semantic HTML that browsers perceive natively. This submit covers easy methods to construct a customized toggle the use of Divi 5’s Part Sort settings, Divi design settings, and a few easy CSS to make all of it in reality clean.

Figuring out The Main points And Abstract Components

The <particulars> detail creates a disclosure widget that customers can open and shut. The <abstract> detail supplies the clickable label that toggles visibility of the content material enclosed inside of <particulars>. The whole thing within <particulars> that isn’t the <abstract> stays hidden till the person clicks to enlarge it.

Browsers render a small disclosure triangle subsequent to the abstract textual content. Clicking anyplace at the abstract toggles the visibility of the rest content material. The detail is keyboard-accessible by means of nature, and display screen readers can announce the expanded or collapsed state by the use of local semantics. That implies you in most cases shouldn’t have ARIA to be in contact the open or closed state, for the reason that parts do this natively.

The <particulars> detail additionally accepts an open characteristic to show the content material expanded by means of default. Including a shared identify characteristic to more than one <particulars> parts teams them into an unique accordion the place just one will also be open at a time. It is a more moderen enhancement, so check if you wish to have to beef up older browsers.

Construction Toggles With Divi 5’s Semantic Components

This means makes use of Divi 5’s Part Sort technique to assign semantic HTML tags to bins and modules. The result’s a toggle constructed completely inside the Visible Builder that outputs correct <particulars> and <abstract> markup. This isn’t the use of the Toggle Module in any respect — only a Staff and a few Textual content Modules.

See also  Divi Product Highlight: Milly Child Theme

Surroundings Up The Construction

The toggle calls for 3 parts: a Group Module that turns into the <particulars> wrapper, a kid detail that turns into the <abstract> label, and a sibling detail that holds the collapsible content material.

Upload a Row for your web page with a single-column structure. Within that Column, upload a Staff Module. This Staff will function the outer <particulars> container. The usage of a Staff Module as a substitute of the Column itself means that you can stack more than one toggles inside of the similar Column.

Cross forward and magnificence your heading if you wish to have to make it simple to learn.

Changing The Staff To A Main points Part

Click on the Staff Module to open its settings. Navigate to the Complicated tab and find the HTML possibility staff. Click on the Part Sort dropdown and make a choice particulars from the to be had choices.

This adjustments the Staff’s HTML output from a generic <div> to a <particulars> detail. The Staff keeps all its visible styling and structure functions whilst gaining the local toggle habits.

Including The Abstract Part

Throughout the Staff, upload a Textual content Module. This module will change into the clickable toggle header. Open the Textual content Module settings and move to the Complicated tab. Within the HTML possibility staff, alternate the Part Sort to abstract. Go back to the Content material tab and input your toggle header textual content. This newsletter turns into the clickable label that customers engage with to enlarge and cave in the toggle.

At this level, the toggle seems damaged — no disclosure triangle, and clicking does not anything. As a result of we used a pre-existing module, some kinds struggle with the browser-native element and abstract parts.  Alternatively, we’ll be customizing the toggle ourselves anyway, so we’ll repair the whole lot with customized CSS. This may give us extra techniques to genre it.

Including The Collapsible Content material

Upload any other Textual content Module within the similar Staff, situated underneath the abstract Textual content Module. This module holds the content material that looks when the toggle is expanded. Go away the Part Sort at its default of <div>. Input the content material you need to show when the toggle is opened. This will come with formatted textual content, hyperlinks, or any content material the Textual content Module helps. You’ll be able to additionally upload further modules (photographs, buttons, and many others.).

See also  Website online Site visitors Down? Easy methods to Diagnose and Repair Site visitors Drops

Including The Disclosure Chevron

Let’s upload some elementary kinds to the Staff, together with a background colour, padding (simply at the best, left, and proper, no longer the ground), and a border radius.

Now onto the toggle. The toggle wishes CSS to show a visible indicator. This CSS provides a chevron from Divi’s integrated icon font that sits after the abstract textual content and flips 180 levels when the toggle opens. Upload it to the Column protecting the toggles underneath Complicated > CSS > Unfastened-Shape CSS:

particulars > abstract {
 list-style: none;
 cursor: pointer;
}

particulars > abstract::-webkit-details-marker {
 show: none;
}

particulars > abstract::after {
 content material: "33";
 font-family: "ETmodules";
 font-size: 24px;
 margin-left: 10px;
 transition: grow to be 0.3s ease;
 line-height: 1;
 show: flex;
 align-items: middle;
 justify-content: middle;
}

particulars[open] > abstract::after {
 grow to be: rotate(180deg);
}

.et_pb_group > :no longer(abstract) {
 padding-bottom: clamp(0.7rem, 0.6rem + 0.6vw, 1.1rem);
}

Add Toggle CSS to the Column Housing the Group

Let me provide an explanation for each and every a part of the code and display you what each and every does via successive movies.

First, we utterly take away the default triangle used. We will be able to use our personal icon. Marker rendering and styling range by means of browser, so this CSS gets rid of them the place supported and replaces them with a constant icon. Divi features a customized icon font called ETmodules. As an alternative of usual characters, this font maps particular keys to icons already loaded up by the use of the Theme. Surroundings the font-family to “ETmodules” and the content material to “33” renders a downward-pointing chevron.

Now, within the <abstract> Textual content Module, set show to Flex and set flex-direction to Row. Whilst in Structure choices, set Justify Content material to House Between. This helps to keep the textual content and chevron aligned at the similar line, with the ::after pseudo-element putting the icon after the abstract textual content, and pushes the textual content and icon to the sides.

The following a part of the CSS is accountable for the animation when the toggle is clicked. We use a grow to be to rotate it 180 levels when expanded, so the chevron issues down when collapsed and up when open.

Finally, there may be CSS that selects all goods inside the staff (with the exception of for anything else wrapped within the <abstract> tag) and applies backside padding to each and every merchandise. This automates assigning the padding after each and every kid detail, so that you don’t need to do it manually.

No longer important, however if you wish to visually divide the abstract from the content material, upload a backside border to the abstract Textual content Module. Within the Design tab, move to the Border possibility staff. To find the Backside Border settings space and set its width to 1px. Transfer to the Spacing possibility staff and set the ground padding to clamp(0.7rem, 0.6rem + 0.6vw, 1.1rem).

See also  15 Best WordPress Newsletter Email Optin Plugins in 2023

And, if we would have liked more than one toggles in this web page, we will be able to merely reproduction the gang and alter the content material inside of.

Now, we will be able to upload a picture beneath the second one Textual content Module, simply to turn that more than one content material varieties and modules can be utilized within the toggle.

Sensible Use Circumstances For HTML Toggles

Browser-native <particulars> and <abstract>  tags be offering a light-weight, available answer for organizing content material with out the efficiency price of JavaScript. Whilst maximum usually used for Steadily Requested Questions — incessantly used for FAQ sections, and you’ll be able to pair them with FAQ structured information if you’re deliberately including schema markup.

Assume you wish to have to cover dense technical specs, guaranty particulars, or “beginner-level” context in documentation in order that complicated customers can scan the web page successfully.

This Part combo additionally successfully manages display screen actual property by means of tucking away spoilers and puzzle answers, collapsing long video transcripts or huge code blocks in technical tutorials, or even simplifying cellular interfaces by means of housing complicated e-commerce filters or navigation menus in the back of a blank, interactive label.

Take a look at Semantic Components In Divi 5 These days!

Divi 5‘s Semantic Components function allows you to construct with local HTML immediately within the Visible Builder. The <particulars> and <abstract> parts ship available, JavaScript-free toggles that paintings in all trendy browsers. For those who have been on the lookout for a lighter-weight choice to the Toggle Module, this is a wonderful possibility for you currently.

Take a look at it to your subsequent FAQ segment or product web page — the setup takes mins, and the result’s cleaner markup than any plugin can be offering.

The submit How To Create Browser-Native Toggles Using Divi 5’s Semantic Tags gave the impression first on Elegant Themes Blog.

WordPress Maintenance Plans | WordPress Hosting

read more

0 Comments

Submit a Comment

DON'T LET YOUR WEBSITE GET DESTROYED BY HACKERS!

Get your FREE copy of our Cyber Security for WordPress® whitepaper.

You'll also get exclusive access to discounts that are only found at the bottom of our WP CyberSec whitepaper.

You have Successfully Subscribed!