Examples of text styling and inline formatting elements
Basic text formatting elements for emphasis and styling.
Strong("Bold text using Strong")
Em("Italic text using Em")
Mark("Highlighted text using Mark")
Small("Small text using Small")
// Combined formatting
P {
Text("This paragraph contains ")
Strong("bold")
Text(", ")
Em("italic")
Text(", and ")
Mark("highlighted")
Text(" text.")
}
<strong>Bold text using Strong</strong>
<em>Italic text using Em</em>
<mark>Highlighted text using Mark</mark>
<small>Small text using Small</small>
<p>This paragraph contains <strong>bold</strong>, <em>italic</em>, and <mark>highlighted</mark> text.</p>
This paragraph contains bold, italic, and highlighted text.
Code elements for displaying inline code and code blocks.
// Inline code
P {
Text("Use ")
Code("let x = 42")
Text(" to declare a constant.")
}
// Code block with Pre
Pre {
Code("""
func greet(name: String) -> String {
return "Hello, \(name)!"
}
""")
}
// Preformatted text without code
Pre("""
ASCII Art Example:
_____
/ \
| ^ ^ |
| > |
\_____/
""")
<p>Use <code>let x = 42</code> to declare a constant.</p>
<pre><code>func greet(name: String) -> String {
return "Hello, \(name)!"
}</code></pre>
<pre> ASCII Art Example:
_____
/ \
| ^ ^ |
| > |
\_____/</pre>
Use let x = 42
to declare a constant.
func greet(name: String) -> String {
return "Hello, \(name)!"
}
ASCII Art Example: _____ / \ | ^ ^ | | > | \_____/
Elements for quotations and citations.
// Block quote
BlockQuote {
P("The only way to do great work is to love what you do.")
P("- Steve Jobs")
}
// Inline quote
P {
Text("As Einstein said, ")
Q("Imagination is more important than knowledge.")
}
// Cite element
P {
Q("To be or not to be")
Text(" from ")
Cite("Hamlet")
}
<blockquote>
<p>The only way to do great work is to love what you do.</p>
<p>- Steve Jobs</p>
</blockquote>
<p>As Einstein said, <q>Imagination is more important than knowledge.</q></p>
<p><q>To be or not to be</q> from <cite>Hamlet</cite></p>
The only way to do great work is to love what you do.
- Steve Jobs
As Einstein said, Imagination is more important than knowledge.
To be or not to be
from Hamlet
Subscript and superscript for scientific notation and footnotes.
// Chemical formula
P {
Text("Water is H")
Sub("2")
Text("O")
}
// Mathematical expression
P {
Text("E = mc")
Sup("2")
}
// Footnote reference
P {
Text("This needs a citation")
Sup {
Link(href: "#ref1", "[1]")
}
}
<p>Water is H<sub>2</sub>O</p>
<p>E = mc<sup>2</sup></p>
<p>This needs a citation<sup><a href="#ref1">[1]</a></sup></p>
Elements for showing document edits and changes.
// Track changes
P {
Text("The event is on ")
Del("Saturday")
Text(" ")
Ins("Sunday")
Text(".")
}
// With attributes
P {
Text("Price: ")
Del {
Text("$99")
}
.attribute("datetime", "2025-01-01")
Text(" ")
Ins {
Text("$79")
}
.attribute("datetime", "2025-01-15")
}
// Strike through (using Del as alternative)
Del("This text is no longer accurate")
<p>The event is on <del>Saturday</del> <ins>Sunday</ins>.</p>
<p>Price: <del datetime="2025-01-01">$99</del> <ins datetime="2025-01-15">$79</ins></p>
<del>This text is no longer accurate</del>
The event is on Saturday Sunday.
Price: $99 $79
Elements for abbreviations, definitions, and annotations.
// Abbreviation with title
P {
Text("The ")
Abbr("HTML", title: "HyperText Markup Language")
Text(" specification is maintained by the W3C.")
}
// Keyboard shortcut with Kbd
P {
Text("Press ")
Kbd("Ctrl")
Text(" + ")
Kbd("C")
Text(" to copy.")
}
<p>The <abbr title="HyperText Markup Language">HTML</abbr> specification is maintained by the W3C.</p>
<p>Press <kbd>Ctrl</kbd> + <kbd>C</kbd> to copy.</p>
The HTML specification is maintained by the W3C.
Press Ctrl + C to copy.
Special purpose text elements for technical content.
// Keyboard input
P {
Text("Press ")
Kbd("Cmd")
Text(" + ")
Kbd("S")
Text(" to save.")
}
// Sample output
P {
Text("The command outputs: ")
Samp("Hello, World!")
}
// Variable
P {
Text("The ")
Var("x")
Text(" variable stores the result.")
}
// Time element
P {
Text("Published on ")
Time("January 1, 2025", datetime: "2025-01-01")
}
// Data element with value
P {
Text("Product ID: ")
Data("12345", value: "prod-12345")
}
<p>Press <kbd>Cmd</kbd> + <kbd>S</kbd> to save.</p>
<p>The command outputs: <samp>Hello, World!</samp></p>
<p>The <var>x</var> variable stores the result.</p>
<p>Published on <time datetime="2025-01-01">January 1, 2025</time></p>
<p>Product ID: <data value="prod-12345">12345</data></p>
Press Cmd + S to save.
The command outputs: Hello, World!
The x variable stores the result.
Published on
Product ID: 12345