Esta página foi traduzida do inglês pela comunidade. Saiba mais e junte-se à comunidade MDN Web Docs.

View in English Always switch to English

String.prototype.sub()

Deprecated

Avoid using this feature in new projects. HTML wrapper methods exist only for backwards compatibility. Use DOM APIs to create elements instead. This feature may be a candidate for removal from web standards or browsers.

Consider using the following features instead: DOM.

O método sub() cria um elemento HTML <sub> que faz com que uma string seja exibida como subscrito (texto pequeno).

Sintaxe

str.sub()

Valor retornado

Uma string contendo um elemento HTML <sub>.

Descrição

O método sub() cria uma string dentro de uma tag <sub>: "<sub>str</sub>".

Exemplos

Usando os métodos sub() e sup()

Os exemplos seguintes usam o métodos sub() e sup() para formatar uma string:

js
var superText = "superscript";
var subText = "subscript";

console.log("This is what a " + superText.sup() + " looks like.");
// This is what a <sup>superscript</sup> looks like

console.log("This is what a " + subText.sub() + " looks like.");
// This is what a <sub>subscript</sub> looks like.

Especificações

Specification
ECMAScript® 2027 Language Specification
# sec-string.prototype.sub

Veja também