0

How can I format a typical Input with type="button" to display content text having a subscript format?

Example: O2

2 Answers 2

1

See this fiddle

You can use HTML <sub> to insert subscript. See the below given HTML

HTML

<button type="button">
  O<sub>2</sub>
</button>

Read more about <sub> in the docs

Sign up to request clarification or add additional context in comments.

Comments

1

For that particular example you could just use Unicode code point U+2082:

    <input type="button" value="O₂">

… but in the general case the solution is stop using an input. HTML 4 introduced the <button> element to replace the submit, button and reset types.

<button> has two main advantages:

  • The value and display content can be different
  • The display content can include markup

<button type="button"> O<sub>2</sub> </button>

1 Comment

Thank you @Lal & Quentin. I spent the afternoon exploring all sorts of options and did indeed move to using <Button type=Button> for better flexibility. Interestingly, the O<sub>2</sub> has an odd behavior onkeydown: The "O" moves but the "2" remains static. Therefore the Entity ID (whether Unicode or HTML) actually works better. In addition, I experimented further with the innerHTML to include Font Awesome compilations with great success. Quirky fun :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.