---
title: "Subscript and Superscript"
canonical: https://www.graphicsmill.com/samples/Text/EnhancedText/SubscriptSuperscript_cs
product: "Graphics Mill"
source: "Text/EnhancedText/SubscriptSuperscript.cs"
---

# Subscript and Superscript

Draws subscript and superscript text.

## Instruction

This code demonstrates the use of superscript and subscript formatting in text rendering.

## Usings

```csharp
using Aurigma.GraphicsMill.Drawing;
```

## Code Snippet

```csharp
// Here one may find all possible tags
// https://www.graphicsmill.com/docs/gm/advanced-formatted-text.htm

using (var bitmap = new Bitmap(200, 200, PixelFormat.Format24bppRgb, RgbColor.White))
using (var gr = bitmap.GetGraphics())
{
    var text = new PlainText("X<span style='sup:true;sup-position:0.333;sup-size:0.583'>2</span>\nX<span style='sub:true;sub-position:0.333;sub-size:0.583'>2</span>", gr.CreateFont("Verdana", 50))
    {
        Position = new System.Drawing.PointF(30, 80),
    };

    gr.DrawText(text);

    bitmap.Save("SubscriptSuperscript.png");
}
```

## Explanation

The code:

- Creates a `Bitmap` object with a white background (`RgbColor.White`) and dimensions of 200x200 pixels.
- Initializes an `AdvancedGraphics` object for drawing on the bitmap.
- Defines a `PlainText` object with the string "X2" and applies HTML-like tags to render the "2" as a superscript (`sup:true`) and subscript (`sub:true`) with specified positions and sizes.
- The superscript is positioned at 33% of the height and resized to 58.3% of the original font size, while the subscript follows a similar positioning and sizing.
- The text is drawn on the bitmap at the position `(30, 80)` with a font size of 50 points using the "Verdana" font.
- The final image is saved as a PNG file (`SubscriptSuperscript.png`).

## Tags

- [Formatted Text](<https://www.graphicsmill.com/samples/tags/formatted-text_md>): XML-based formatted text syntax
- [Text](<https://www.graphicsmill.com/samples/tags/text_md>): Rendering and formatting text

## Output

- [SubscriptSuperscript.png](<https://www.graphicsmill.com/samples/Text/compiled/Debug/SubscriptSuperscript_png>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Bitmap.GetGraphics](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Bitmap_GetGraphics.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.CreateFont(String,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_CreateFont_2_1dbfa9fa.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.DrawText(Text)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_DrawText_1_f576d03f.htm.md>)
- [Aurigma.GraphicsMill.Drawing.PlainText](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_PlainText.htm.md>)
- [Aurigma.GraphicsMill.Drawing.PlainText.Position](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_PlainText_Position.htm.md>)
