Enable with .UseGenericAttributes() (included in UseAdvancedExtensions()).
This extension allows attaching CSS classes, IDs, and arbitrary HTML attributes to nearly any Markdown element using {...} syntax. Inspired by PHP Markdown Extra — Special Attributes.
UseGenericAttributes() should be the last extension added to the pipeline, as it modifies other parsers to recognize attribute syntax.
Place {...} after a Markdown element:
# Heading {#custom-id .special-class}
A paragraph with attributes. {.lead}
[A link](https://example.com){target="_blank" rel="noopener"}
| Syntax | Meaning | Example |
|---|---|---|
#value |
HTML id |
{#my-id} |
.value |
CSS class | {.my-class} |
key=value |
HTML attribute | {data-count=5} |
key="value" |
Quoted attribute | {title="Hello World"} |
Multiple attributes can be combined:
A paragraph. {#intro .highlight data-section="overview"}
## My Section {#section-1 .special}
Renders as: <h2 id="section-1" class="special">My Section</h2>
Place the attributes at the end of the paragraph:
This is a styled paragraph. {.lead .text-center}
```csharp {.highlight-lines}
var x = 42;
```
> A styled blockquote {.fancy-quote}
The .table class is commonly used to apply Bootstrap-style table formatting:
{.table .table-striped}
| A | B |
|---|---|
| 1 | 2 |
[Click me](https://example.com){.btn .btn-primary}
{.rounded width="200"}
**Important text**{.text-danger}
A paragraph. {.lead #intro}
Produces:
<p class="lead" id="intro">A paragraph.</p>