translate
Lets you turn off automatic translation of a part of the page, for example a brand name or code.
- Applies to
- All HTML elements
Example
#<style>
[translate="no"] { border-bottom: 1px dashed #a78bfa; }
</style>
<p>
Welcome to <span translate="no">CodeWorlds</span>! In this lesson you will learn the
<code translate="no">document.querySelector()</code> method.
</p>
<p>Lesson author: <span translate="no">Anna Kowalczyk</span></p>The underline comes from the style in the example and marks the fragments with translate="no". When someone translates the page in the browser, the site name, the code and the surname stay in the original, while the rest of the text changes language.
Definition and usage
#The translate attribute tells automatic translation tools whether the element’s content should be translated. The value no means “leave it in the original”. It is respected by the translators built into browsers, such as the one in Chrome, and by many services that translate whole pages.
It is useful wherever translation breaks something: in brand and product names that are ordinary words, in surnames, in addresses, and above all in code snippets. A translator does not tell code from ordinary text, so it can translate function names and keywords, and such code stops working once copied.
All the elements inside inherit the setting. If you turn translation off for a larger block, you can turn it back on inside it with translate="yes". When nobody translates the page, the attribute changes nothing, in either look or behavior.
Syntax
#<element translate="yes | no">…</element>Values
#yes
or empty
The content can be translated. This is the default, so you write this value mainly to turn translation back on inside a block withtranslate="no".no
The content stays in the original, along with all the elements inside.
More examples
#<!DOCTYPE html>
<html lang="en" translate="no">
<head>
<meta charset="utf-8">
<meta name="google" content="notranslate">
<title>Project source code | CodeWorlds</title>
</head>
<body>…</body>
</html>The attribute on the <html> element turns off translation of the whole page. The <meta name="google" content="notranslate"> tag does the same, but only Google understands it.
Browser support
#Widely available · since 2023
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- On course and documentation pages, mark code blocks (
<pre>,<code>) withtranslate="no". A reader using translation then gets code that works when copied. - Some tools, including Google Translate, also recognize the
notranslateclass. To be safe, you can add both:translate="no" class="notranslate". - Do not turn off translation of a whole page without a good reason. For many people automatic translation is the only way to understand it.
Related entries
#- langThe language of the element’s content, for example pl or en.
- <code>A piece of computer code: the name of a variable, function, tag, or file, as well as a short listing.
- <pre>Preformatted text: it preserves spaces, tabs, and line breaks exactly as they appear in the code.
- <html>The root of an HTML document. Every other element on the page lives inside it.
Spotted a mistake or missing an example? Write to us.