Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use superscript in an html text input tag?

I've got a simple input tag (which I prettify using Bootstrap) in which I now want to place a superscript (to display "m2"). The problem is that when I do this:

<input class="form-control" name="gla" placeholder="m<sup>2</sup>" type="text">

the placeholder literally shows this: m<sup>2</sup>

Does anybody know how I can properly display the superscript? All tips are welcome!

like image 302
kramer65 Avatar asked Dec 03 '14 11:12

kramer65


People also ask

How do you add superscript to text in HTML?

Superscript: The <sup> tag is used to add a superscript text to the HTML document. The <sup> tag defines the superscript text. Superscript text appears half a character above the normal line and is sometimes rendered in a smaller font.

How do you superscript in text field?

Apply superscript or subscript formatting to text Select the character that you want to format as superscript or subscript. On the Home tab, in the Font group, pick the Font Dialog Box Launcher. On the Font tab, under Effects, select the Superscript or Subscript check box.

Which tag is used to superscript a text in HTML?

<sup>: The Superscript element The <sup> HTML element specifies inline text which is to be displayed as superscript for solely typographical reasons. Superscripts are usually rendered with a raised baseline using smaller text.

How do I make an exponent in HTML?

Note. The HTML <sup> element is found within the <body> tag. The <sup> tag is used to comply with typographical standards or conventions. The <sup> tag is generally used to specify exponents such as m2 and ordinal numbers such as 1st, 2nd or 3rd.


3 Answers

How about using HTML Entities

<input class="form-control" name="gla" placeholder="m&sup2;" type="text">

Yes it works

like image 72
Lekhnath Avatar answered Oct 23 '22 20:10

Lekhnath


You could just use the UTF-8 character for superscripted ². Also be sure to set the charset of the document to UTF-8.

<html>
    <head>
        <meta charset="UTF-8"> 
    </head>
    <body>
        <input class="form-control" name="gla" placeholder="m²" type="text" />
    </body>
</html>

Also this answer might be of help.

like image 29
lmazgon Avatar answered Oct 23 '22 20:10

lmazgon


Within an attribute value, you can use characters just like in document content (except for the quote character used as attribute value delimiter). This means that you can write the superscript two character as such, or using a named character reference, or a numeric reference. When using the character as such, you need to make sure that the character encoding is properly declared (corresponds to the actual encoding).

<input class="form-control" name="gla" placeholder="m²" type="text"><br>
<input class="form-control" name="gla" placeholder="m&sup2;" type="text"><br>
<input class="form-control" name="gla" placeholder="m&#178;" type="text"><br>
<input class="form-control" name="gla" placeholder="m&#xb2;" type="text"><br>
like image 2
Jukka K. Korpela Avatar answered Oct 23 '22 20:10

Jukka K. Korpela