How to Localize HTML5 details, summary, and dialog Elements
Localize native disclosures with <details> and <summary>, and native dialogs with <dialog>. Translate the visible copy and accessible names, but keep the element names, behavior attributes, and values your code depends on unchanged.
The production caveat is that some of the most important strings are hidden at page load. A translation can look complete until someone expands a disclosure, opens a modal, or hears a screen reader announce an untranslated dialog title. Treat each hidden state as part of the translation and review both the copy and the interaction in that state.
Separate translatable strings from behavior
Give translators enough context to distinguish a disclosure label from a dialog title or a button. Keep the question, answer, title, body, and actions as separate translation units. If a sentence contains a link or emphasized phrase, use a rich-text message format that lets translators move the marked phrase within the sentence rather than splitting the sentence into fragments around the tag.
| Markup or value | Localization rule | What to verify |
|---|---|---|
<summary>Shipping options</summary> | Translate the label as a complete phrase. | The collapsed label still tells readers what will expand. |
aria-label="Close dialog" | Translate the attribute value if the control relies on it for its name. | The spoken name matches the control’s purpose and language. |
aria-labelledby="discard-title" | Keep the ID reference fixed; translate the referenced heading. | The reference matches a unique id="discard-title". |
<details open> and name="delivery-options" | Keep state and grouping under application control. | The intended disclosure starts open, and unrelated groups stay independent. |
method="dialog" and value="discard" | Keep the form method and machine-readable action value; translate the button text. | Changing the label doesn’t change the result handled by JavaScript. |
lang="ar" and dir="rtl" | Set these from locale metadata rather than translating them as copy. | The content has the correct language and base direction. |
Never translate an ID, an ID reference, or an action value that JavaScript compares. Translate the text the reader sees or hears.
Keep the disclosure label inside the first child
Put <summary> first inside <details>. Give it a label that makes sense in either state: “When will my order arrive?” works whether the answer is hidden or visible, while “Show answer” becomes inaccurate as soon as the disclosure opens.
Broken: the question is outside the toggle
<details>
<p>¿Cuándo llegará el pedido?</p>
<summary>Más información</summary>
<p>La fecha estimada aparece al finalizar la compra.</p>
</details>
The paragraph before <summary> makes the markup nonconforming, even if a browser still renders the toggle. More importantly, the actual question is hidden when the disclosure is closed. A list of controls all named “Más información” gives readers no way to tell which one answers which question.
Fixed: the question is the toggle
<details lang="es">
<summary>¿Cuándo llegará el pedido?</summary>
<p>La fecha estimada aparece al finalizar la compra.</p>
</details>
The question now labels the native control, and the answer remains in the content it reveals. Test it collapsed and expanded using the keyboard; the browser already handles the toggle, so it doesn’t need a custom click handler or a manually updated aria-expanded. On an entirely Spanish page, set lang="es" on <html> instead of repeating it on every disclosure.
If you use the name attribute to make a group of disclosures mutually exclusive, assign the same stable name to members of that group and a different name to unrelated groups. If rendering initial state from a template, emit open only for an expanded item: open="false" is still open because the attribute is present.
Localize the dialog title, actions, and result separately
Render a visible heading and point aria-labelledby at it so the visible and accessible titles come from the same translation. The example below uses a short description to clarify the consequence and puts initial focus on the safer action. For a long dialog with multiple paragraphs or lists, don’t reference the entire body with aria-describedby; let readers navigate that content instead of hearing it flattened into one announcement.
<section lang="fr">
<button type="button" id="open-discard">
Abandonner les modifications…
</button>
<dialog id="discard-dialog"
aria-labelledby="discard-title"
aria-describedby="discard-description">
<h2 id="discard-title">Abandonner les modifications ?</h2>
<p id="discard-description">
Les modifications non enregistrées seront perdues.
</p>
<form method="dialog">
<button type="submit" value="keep" autofocus>
Poursuivre la modification
</button>
<button type="submit" value="discard">
Abandonner les modifications
</button>
</form>
</dialog>
</section>
Both action labels can change without changing the submitted values. The visible heading supplies the dialog’s accessible name, and autofocus selects the non-destructive action when the dialog opens. If this component renders more than once on a page, generate unique IDs per instance and update the references with them.
const trigger = document.querySelector("#open-discard");
const dialog = document.querySelector("#discard-dialog");
trigger.addEventListener("click", () => {
if (dialog.open) return;
dialog.returnValue = "";
dialog.showModal();
});
dialog.addEventListener("close", () => {
if (dialog.returnValue !== "discard") return;
dialog.dispatchEvent(new CustomEvent("discard-confirmed", {
bubbles: true
}));
});
Place this script after the markup or load it as a deferred script. showModal() opens the dialog modally and makes the rest of the document inert; adding open in the markup doesn’t do that. Resetting returnValue prevents a later Escape dismissal from being mistaken for a previous confirmation; have the editor listen for discard-confirmed to perform the actual discard.
Never treat every dialog close as confirmation. Escape and a translated Cancel button must not trigger the destructive action.
Handle text direction and longer labels
Language and direction are separate settings: lang="ar" identifies Arabic, but doesn’t set right-to-left layout. Put dir="rtl" on the document for an RTL page, or on the nearest shared container when the widget is embedded in left-to-right content. Isolate an interpolated identifier with <bdi> so its direction doesn’t pull adjacent punctuation out of place.
<section class="localized-widget" lang="ar" dir="rtl">
<details>
<summary>كيف يمكن تتبّع الطلب؟</summary>
<p>رقم التتبّع: <bdi>AB-2049</bdi>.</p>
</details>
</section>
The container sets the direction for both the summary and the answer while the tracking number stays isolated. Preserve the <bdi> wrapper even when translators move the identifier within the sentence. Verify the colon, hyphen, and period visually; a text-only comparison won’t show their rendered positions.
.localized-widget summary {
padding-block: 0.5rem;
padding-inline: 0.75rem;
text-align: start;
overflow-wrap: anywhere;
}
.localized-widget dialog {
box-sizing: border-box;
inline-size: min(32rem, calc(100% - 2rem));
max-block-size: calc(100% - 2rem);
overflow: auto;
text-align: start;
}
.localized-widget dialog form[method="dialog"] {
display: flex;
flex-wrap: wrap;
gap: 0.75rem;
}
.localized-widget dialog button {
max-inline-size: 100%;
white-space: normal;
overflow-wrap: anywhere;
}
Apply localized-widget to the ancestor of the dialog as well when using these styles. Logical properties follow the writing direction, and the button row wraps instead of clipping longer labels. Keep the native summary marker visible, and check at a narrow viewport and enlarged text size that the dialog can scroll to both actions.
Validate each locale in its interactive states
Use HTML Translate to compare localized markup and spot untranslated labels before testing interactions in the browser.
- Load the localized route with every disclosure initially closed. Open each
<summary>by keyboard and review the revealed paragraphs and links for source-language leftovers. - Open the dialog from its translated trigger. Check that the heading referenced by
aria-labelledbyis announced, then verify the focused control and move through the actions withTabandShift+Tab. - Confirm once, reopen, and press
Escape. Check that dismissal doesn’t emitdiscard-confirmedand that focus returns to the trigger if it’s still available. - Repeat in an RTL locale and a locale with long labels. Check
dir, mixed-direction punctuation, wrapping, and whether every action stays reachable without horizontal scrolling.
Common mistakes and troubleshooting
- The answer is still in the source language. The export captured only visible strings. Extract text from closed
<details>and unopened<dialog>elements in the source markup or component templates. - The disclosure shows a generic browser label. The translated output dropped the author-supplied
<summary>. Restore it as the first child and translate its text rather than relying on the fallback label. - The modal opens but the page behind it is interactive. The code set
openor calledshow(). UseshowModal()for a modal interaction. - A translated button stops triggering its action. The handler compares visible text. Compare
dialog.returnValuewith a stable action token such asdiscard. - The dialog is announced without its title. The heading ID was changed or duplicated. Match
aria-labelledbyto the unique ID of the rendered heading. - Long labels disappear at the edge. A fixed width or
white-space: nowrapprevents wrapping. Allow the actions to wrap and test the result at narrow widths.
HTML5 Details, Summary, Dialog Questions
Should the summary label change when the disclosure opens?
Usually not. A stable question or topic tells readers what the disclosure contains, and the browser exposes its expanded or collapsed state. If the design requires two labels, translate each as a complete message rather than assembling it from translated fragments.
Can the summary contain a link or button?
Keep separate interactive controls out of <summary>. Put links and buttons in the revealed content so readers can clearly distinguish toggling the disclosure from following a link or taking an action.
Does a dialog’s close button need an accessible label?
A button with visible translated text such as Fermer already has a name. An icon-only button needs a localized accessible name, for example aria-label="Fermer la boîte de dialogue" in French.
When should a component have its own language attribute?
Set lang on the nearest container whose language differs from what it inherits. For a page translated into one language, set it on <html>; override it inside the page only for content in a different language.
Can these elements be used in localized marketing email?
Don’t make essential email content depend on <details> or <dialog>. Email clients differ in how they handle interactive markup and generally don’t run the script needed to open a modal. Show essential copy directly and link to the localized web page for the full interaction.