Coding mathematical formulas in HTML is somewhat frustrating because HTML does not support formulas. It is possible to code simple mathematical equations with HTML markup without having to resort to using graphical images. The advantage of HTML and CSS over graphical images is that the display can be enlarged using the browser zoom or text-size options. A quadratic equation is easily coded using the <sup></sup> tag.
ax<sup>2</sup> + bx + c = 0
HTML provides the square root character entity √ (√) which is a single character. In order to code the square root symbol, the characters that follow the square root character must have an overline. This is accomplished by creating a span of characters with a CSS style "text-decoration:overline;" as in the following example:
<span style="white-space: nowrap; font-size:larger"> √<span style="text-decoration:overline;"> X + 1 </span> </span>
Notice that the CSS style includes the nowrap option to keep the browser from splitting up the formula, and the formula within the square root has a leading and trailing non-blank space to extend the overline one character beyond the formula.
If you try to apply the above technique to a formula such as X2 + 1, the results don't look quite right because the overline applied to the superscript may be higher for some browsers, or it may cross over the superscripted characters:
Square Roots with superscripts may be coded using a table with two rows and two columns. The upper row contains to go over the square root symbol and enough underline characters to go over the formula. To avoid problems with rendering on different browsers, the table should use a widely availabe font family such as Verdana or Arial.
| _______ | |
| √ | X2 + 1 |
<table style="border-spacing:0px; border-width:0px; font-family:verdana;">
<tr>
<td>
</td>
<td>
_______
</td>
</tr>
<tr>
<td style="padding:0px; font-size:larger">
√
</td>
<td style="padding:0px;">
X<sup>2</sup> + 1
</td>
</tr>
</table>
A technique that produces good results is to use a <span> tag, instead of the <sup> tag, to control the size and position of the superscripts so that they will not go into the overline. For example:
√<span style="text-decoration:overline"> (<i>a</i><span style="font-size: 10px;vertical-align:+25%;">2.7</span>+ <i>b</i><span style="font-size: 10px;vertical-align:+25%;">8.6</span>) </span>
The table technique may be expanded with additional rows to create quite complex expressions. The quadratic formula can be coded with a row where the overline in the denominator separates the numerator and denominator of the formula.
| −b ± √ b2 − 4ac |
| 2a |
<table style="font-family:verdana;">
<tr>
<td>−b ±
√<span style="text-decoration:overline">
b<span style="font-size: 10px;vertical-align:+25%;">2</span> −
4ac </span></td>
</tr>
<tr>
<td style="text-align:center;">
<span style="text-decoration:overline;">
2a </span>
</td>
</tr>
</table>