The translate Attribute
The translate Attribute
Section titled “The translate Attribute”The translate attribute specifies whether an element’s text content and attribute values should be translated when the page is localized or when using browser translation tools. It’s essential for protecting brand names, technical terms, code examples, and other content that shouldn’t be translated.
Syntax
Section titled “Syntax”<element translate="value">Content</element>Values
Section titled “Values”| Value | Description |
|---|---|
yes (default) | Content should be translated |
no | Content should NOT be translated |
Examples
Section titled “Examples”Brand Names and Product Names
Section titled “Brand Names and Product Names”Code Examples and Technical Documentation
Section titled “Code Examples and Technical Documentation”Personal Names and Places
Section titled “Personal Names and Places”Multi-Language Content
Section titled “Multi-Language Content”When to Use translate=“no”
Section titled “When to Use translate=“no””Always Use translate=“no” For:
Section titled “Always Use translate=“no” For:”✓ Brand names and trademarks: TechPro™, Nike®, Coca-Cola® ✓ Product names: iPhone 15, PlayStation 5 ✓ Person names: María García, João Silva ✓ Place names: São Paulo, München, København ✓ Code examples: variables, functions, syntax ✓ Technical terms: HTML, CSS, JavaScript ✓ Domain names: example.com, github.io ✓ Email addresses: [email protected] ✓ Phone numbers: +1 (555) 123-4567 ✓ Prices and currencies: $99.99, €49,99 ✓ Measurement units: 5kg, 10mph ✓ Serial numbers: ABC-123-DEF
<!-- Brand names --><h1><span translate="no">Nike</span> Running Shoes</h1>
<!-- Code examples --><code translate="no">console.log('Hello')</code>
<!-- Person names --><p>Author: <span translate="no">José García</span></p>
<!-- Places --><address translate="no"> 123 Main Street<br> São Paulo, SP 01234<br> Brazil</address>Allow Translation (translate=“yes” or omit) For:
Section titled “Allow Translation (translate=“yes” or omit) For:”✓ Regular descriptive text ✓ Instructions and help text ✓ UI labels and buttons ✓ Error messages ✓ Marketing copy ✓ Blog posts and articles
<!-- These should be translated --><p>Click the button below to continue.</p><button>Submit Form</button><p class="error">Please enter a valid email address.</p>Best Practices
Section titled “Best Practices”1. Combine with lang Attribute
Section titled “1. Combine with lang Attribute”<!-- Specify language for non-translated content --><blockquote translate="no" lang="fr"> Bonjour, comment allez-vous?</blockquote>
<span translate="no" lang="ja">こんにちは</span>2. Apply to Smallest Necessary Element
Section titled “2. Apply to Smallest Necessary Element”<!-- Good: Specific to brand name --><p>Buy <span translate="no">Nike Air Max</span> shoes today!</p>
<!-- Less ideal: Entire paragraph non-translatable --><p translate="no">Buy Nike Air Max shoes today!</p>3. Use for Technical Documentation
Section titled “3. Use for Technical Documentation”<article> <h2>Using the <code translate="no">fetch()</code> API</h2>
<pre translate="no">fetch('https://api.example.com/data') .then(response => response.json()) .then(data => console.log(data)); </pre>
<p> The <code translate="no">fetch()</code> function returns a Promise that resolves to the Response object. </p></article>4. Protect Attribute Values
Section titled “4. Protect Attribute Values”<!-- Brand name in title attribute --><img src="logo.png" alt="Logo" title="TechPro Inc." translate="no">
<!-- URLs shouldn't be translated --><a href="https://example.com" translate="no"> Visit our website</a>Browser Translation Tools
Section titled “Browser Translation Tools”How Translation Works
Section titled “How Translation Works”Modern browsers offer built-in translation:
- Chrome: Right-click → Translate to [Language]
- Edge: Right-click → Translate to [Language]
- Firefox: Uses extensions like Google Translate
- Safari: Translation via extensions
The translate attribute helps these tools:
- Skip content marked
translate="no" - Maintain proper names and technical terms
- Preserve code examples and identifiers
Inheritance
Section titled “Inheritance”The translate attribute is inherited by descendants:
<!-- All children inherit translate="no" --><div translate="no"> <h1>TechPro X1</h1> <p>$299.99</p> <code>product_id: 12345</code></div>
<!-- Override parent's translate --><div translate="no"> <h1>TechPro X1</h1> <p translate="yes">This description can be translated.</p> <p>But the price: $299.99 cannot be.</p></div>JavaScript API
Section titled “JavaScript API”const element = document.getElementById('myElement');
// Set translateelement.translate = false;element.setAttribute('translate', 'no');
// Get current valueconsole.log(element.translate); // false
// Check if element should be translatedif (element.translate) { console.log('Element can be translated');} else { console.log('Element should not be translated');}Accessibility Considerations
Section titled “Accessibility Considerations”Screen Readers
Section titled “Screen Readers”The translate attribute:
- Does not affect screen reader behavior
- Is only a hint for translation tools
- Should still be combined with proper semantic HTML
<button translate="no" aria-label="Play"> ▶</button>Language Identification
Section titled “Language Identification”Always use lang attribute with translate="no":
<!-- Helps screen readers pronounce correctly --><span translate="no" lang="es">Hola</span><span translate="no" lang="fr">Bonjour</span><span translate="no" lang="de">Guten Tag</span>Common Pitfalls
Section titled “Common Pitfalls”Testing Translation Behavior
Section titled “Testing Translation Behavior”Manual Testing
Section titled “Manual Testing”- Chrome: Right-click page → “Translate to [language]”
- Edge: Similar to Chrome
- Online tools: Google Translate, DeepL, etc.
- Check: Verify translate=“no” content remains unchanged
Automated Testing
Section titled “Automated Testing”// Check if translate attribute is set correctlyconst brandNames = document.querySelectorAll('.brand-name');brandNames.forEach(element => { if (element.translate !== false) { console.warn('Brand name missing translate="no":', element); }});Browser Support
Section titled “Browser Support”Universal support across modern browsers:
| Browser | Support | Notes |
|---|---|---|
| Chrome | 19+ | Full support |
| Firefox | 66+ | Full support |
| Safari | No | Doesn’t support translate attribute |
| Edge | 79+ | Full support |