The valid_elements option defines which elements will remain in the edited text when the editor saves. You can use this to limit the returned HTML to a subset.

This option contains a comma separated list of element conversion chunks. Each chunk contains information about how one element and its attributes should be treated. The default rule set for this option is a mixture of the full HTML5 and HTML4 specification or the HTML5 or HTML4 specification depending on the configured schema.

If you just want to add or change some behaviour for a few items, use the extended_valid_elements option

Control characters:


Rules with this name will be applied to all elements defined after this rule. So @[attr1|attr2] will enable attr1 and attr2 for all elements, but element1,@[attr1|attr2],element2,element3 will enable attr1 and attr2 only for element2 and element3.

If applied in extended_valid_elements, it is only effective for the elements in the extended_valid_elements list.

, Separates element chunk definitions.
/ Separates element synonymous. The first element is the one that will be output.
| Separates attribute definitions.
[ Starts a new attribute list for an element definition.
] Ends an attribute list for an element definition.
! Makes attributes required. If none of the required attributes are set, the element will be removed. For example, "!href".
= Makes the attribute default to the specified value. For example, "target=_blank"
: Forces the attribute to the specified value. For example, "border:0"
< Verifies the value of an attribute (only the listed values are allowed). For example, "target<_blank?_self"
? Separates attribute verification values. See above.
+ Makes the element open if no child nodes exists. For example, "+a".
- Enables removal of empty elements such as <strong />. For example, "-strong".
# Enables padding of empty elements. This will pad with &nbsp; if they are empty. For example, "#p".
! Enables removal of elements with no attributes such as <span>. They can still have content though.

Wildcards such as *,+,? may be used in element or attribute name matching.

Special variables:

{$uid} Results in a unique ID. For example, "p[id:{$uid}]".

Use *[*] to include all elements and all attributes. This can be very useful when used with the invalid_elements option. Example of usage of the valid_elements option:

This example string tells TinyMCE to remove all elements that are not a "a, strong, div or br" element, convert "b" elements to "strong" elements, default "target" to "_blank" and keep the "href", "target" and "align" attributes of the elements.

        valid_elements : "a[href|target=_blank],strong/b,div[align],br"

Duplicate Attribute Warning

Be careful not to duplicate attributes in the definitions as this may cause tinyMCE to render duplicate attributes in the output. For example, if you have

 ... //bad code: dir and style listed twice

then if you happen to have a <blockquote> element in your code with style= or dir= attributes, the editor will cause each of those attributes to be duplicated in the output, which will result in invalid XHTML.