Translate Attribute in HTML: What It Is and How to Use It
translate attribute in HTML tells browsers and translation tools whether the content of an element should be translated or not. It accepts values "yes" (default) to allow translation and "no" to prevent translation of that element's text.How It Works
The translate attribute acts like a sign on a piece of text telling translation tools if they should translate it or leave it as is. Imagine you have a book with some words in a foreign language and some brand names or code snippets that should stay the same. The translate attribute helps keep those parts unchanged.
By default, browsers and translation services assume all text can be translated (translate="yes"). But if you set translate="no" on an element, it signals that the text inside should remain exactly as written, no matter what language the page is translated into.
This is useful for things like product names, technical terms, or any text that should not change meaning or style when translated.
Example
This example shows a paragraph with a brand name that should not be translated.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Translate Attribute Example</title> </head> <body> <p>This is a product from <span translate="no">OpenAI</span> that helps with AI tasks.</p> </body> </html>
When to Use
Use the translate attribute when you want to control which parts of your webpage get translated by browsers or translation tools. This is especially helpful for:
- Brand names or trademarks that should stay the same in all languages.
- Technical terms, code snippets, or product codes that lose meaning if translated.
- Proper nouns like person names or place names that should not be changed.
- UI elements or buttons where translation might confuse users.
By marking these elements with translate="no", you keep your content clear and consistent across languages.
Key Points
- The
translateattribute controls if text is translated or not. - Default value is
"yes", meaning text is translatable. - Set
translate="no"to keep text unchanged during translation. - Useful for brand names, technical terms, and proper nouns.
- Helps improve clarity and user experience in multilingual sites.