title: Attribute Lists Extension # Attribute Lists ## Summary The Attribute Lists extension adds a syntax to define attributes on the various HTML elements in markdown's output. This extension is included in the standard Markdown library. !!! Note This extension is in __maintenance mode__. We will continue to fix bugs and keep it up-to-date with the core parser, but no new features or changes in behavior will be made. If you need a feature that this extension does not offer, then you have three options (1) find an existing [third-party extension] which meets your needs, (2) [build your own extension], or (3) fork this extension (pursuant to its licensing requirements) and maintain it as a third-party extension. [third-party extension]: index.md#third-party-extensions [build your own extension]: api.md ## Syntax The basic syntax was inspired by Maruku's Attribute Lists feature (see [web archive][Maruku]). [Maruku]: https://web.archive.org/web/20170324172643/http://maruku.rubyforge.org/proposal.html ### The List An example attribute list might look like this: ```text {: #someid .someclass somekey='some value' } ``` A word which starts with a hash (`#`) will set the id of an element. A word which starts with a dot (`.`) will be added to the list of classes assigned to an element. A key/value pair (`somekey='some value'`) will assign that pair to the element. Be aware that while the dot syntax will add to a class, using key/value pairs will always override the previously defined attribute. Consider the following: ```text {: #id1 .class1 id=id2 class="class2 class3" .class4 } ``` The above example would result in the following attributes being defined: ```text id="id2" class="class2 class3 class4" ``` HTML includes support for some attributes to be a single term, like `checked`, for example. Therefore, the attribute list `{: checked }` would result in `checked` if the [output format](../reference.md#output_format) is `html` or `checked="checked"` if the output format is `xhtml`. Curly braces can be backslash escaped to avoid being identified as an attribute list. ```text \{ not an attribute list } ``` Opening and closing curly braces which are empty or only contain whitespace are ignored whether they are escaped or not. Additionally, any attribute lists which are not located in the specific locations documented below are ignored. The colon after the opening brace is optional, but is supported to maintain consistency with other implementations. Therefore, the following is also a valid attribute list: ```text { #someid .someclass somekey='some value' } ``` In addition, the spaces after the opening brace and before the closing brace are optional. They are recommended as they improve readability, but they are not required. The Attribute List extension does not have any knowledge of which keys and/or values are valid in HTML. Therefore, it is up to the document author to ensure that valid keys and values are used. However, the extension will escape any characters in the key which are not valid by replacing them with an underscore. Multiple consecutive invalid characters are reduced to a single underscore. ### Block Level To define attributes for a block level element, the attribute list should be defined on the last line of the block by itself. ```text This is a paragraph. {: #an_id .a_class } ``` The above results in the following output: ```html
This is a paragraph.
``` An exception is headers, as they are only ever allowed on one line. ```text A setext style header {: #setext} ================================= ### A hash style header ### {: #hash } ``` The above results in the following output: ```html| set on td | set on em |
|---|---|
| a | b |