smail/attribute

Types

pub type Attribute =
  @internal Attribute

Values

pub fn abbr(value: String) -> Attribute

A short, abbreviated description of the header cell’s content provided as an alternative label to use for the header cell when referencing the cell in other contexts. Some user-agents, such as speech readers, may present this description before the content itself.

pub fn alt(text: String) -> Attribute

Specifies text that should be displayed when the image cannot be rendered. This attribute is essential for accessibility, providing context about the image to users who cannot see it, including those using screen readers.

pub fn aria(name: String, value: String) -> Attribute

Add an aria-* attribute to an HTML element. The key will be prefixed by aria-.

pub fn aria_describedby(value: String) -> Attribute

The global aria-describedby attribute identifies the element (or elements) that describes the element on which the attribute is set.

pub fn aria_description(value: String) -> Attribute

The global aria-description attribute defines a string value that describes or annotates the current element.

pub fn aria_hidden(value: Bool) -> Attribute

The aria-hidden state indicates whether the element is exposed to an accessibility API.

pub fn aria_label(value: String) -> Attribute

The aria-label attribute defines a string value that can be used to name an element, as long as the element’s role does not prohibit naming.

pub fn aria_labelledby(value: String) -> Attribute

The aria-labelledby attribute identifies the element (or elements) that labels the element it is applied to.

pub fn aria_level(value: Int) -> Attribute

The aria-level attribute defines the hierarchical level of an element within a structure.

pub fn aria_roledescription(value: String) -> Attribute

The aria-roledescription attribute defines a human-readable, author-localised description for the role of an element.

pub fn attribute(name: String, value: String) -> Attribute
pub fn background(url: String) -> Attribute

Specifies a background image URL using an HTML attribute. Used on tables and table cells for email clients that support it.

pub fn cellpadding(value: Int) -> Attribute

Specifies the space between the cell walls and the cell content in a table. Works in email clients where CSS padding on cells may not be fully supported.

pub fn cellspacing(value: Int) -> Attribute

Specifies the space between cells in a table. Works in email clients where CSS margin on cells may not be supported.

pub fn charset(value: String) -> Attribute

Declares the character encoding used in the document. When used with a meta element, this replaces the need for the http_equiv("content-type") attribute.

pub fn class(name: String) -> Attribute

A class is a non-unique identifier for an element primarily used for styling purposes. You can provide multiple classes as a space-separated list and any style rules that apply to any of the classes will be applied to the element.

To conditionally toggle classes on and off, you can use the classes function instead.

Note: Classes are not well supported accross all emails clients. Prefer to avoid them when possible in favor of the style module

Note: unlike most attributes, multiple class attributes are merged with any existing other classes on an element. Classes added later in the list will override classes added earlier.

pub fn classes(names: List(#(String, Bool))) -> Attribute

A class is a non-unique identifier for an element primarily used for styling purposes. You can provide multiple classes as a space-separated list and any style rules that apply to any of the classes will be applied to the element. This function allows you to conditionally toggle classes on and off.

Note: Classes are not well supported accross all emails clients. Prefer to avoid them when possible in favor of the style module

Note: unlike most attributes, multiple class attributes are merged with any existing other classes on an element. Classes added later in the list will override classes added earlier.

pub fn colspan(value: Int) -> Attribute

A non-negative integer value indicating how many columns the header cell spans or extends. The default value is 1. User agents dismiss values higher than 1000 as incorrect, defaulting such values to 1.

pub fn content(value: String) -> Attribute

Specifies the value of the meta element, which varies depending on the value of the name or http-equiv attribute.

pub fn datetime(value: String) -> Attribute

Indicates the time and/or date of a <time> element. Values may be one of the following formats:

DescriptionSyntaxExamples
Valid month stringYYYY-MM2011-11, 2013-05
Valid date stringYYYY-MM-DD1887-12-01
Valid local date and time stringYYYY-MM-DD HH:MM, YYYY-MM-DD HH:MM:SS, YYYY-MM-DD HH:MM:SS.mmm, YYYY-MM-DDTHH:MM, YYYY-MM-DDTHH:MM:SS, YYYY-MM-DDTHH:MM:SS.mmm2013-12-25 11:12, 1972-07-25 13:43:07, 1941-03-15 07:06:23.678, 2013-12-25T11:12, 1972-07-25T13:43:07, 1941-03-15T07:06:23.678
Valid global date and time stringA valid local date and time string followed by a valid time-zone offset string2013-12-25 11:12+0200, 1972-07-25 13:43:07+04:30, 1941-03-15 07:06:23.678Z, 2013-12-25T11:12-08:00
Valid week stringYYYY-WWW2013-W46

A comprehensive list of valid formats can be found on MDN.

pub fn dir(direction: String) -> Attribute

Specifies the text direction of the element’s content. The following values are accepted:

ValueDescription
“ltr”The element’s content is left-to-right.
“rtl”The element’s content is right-to-left.
“auto”The element’s content direction is determined by the content itself.

Note: the "auto" value should only be used as a last resort in cases where the content’s direction is truly unknown. The heuristic used by browsers is naive and only considers the first character available that indicates the direction.

pub fn headers(ids: List(String)) -> Attribute

A list of space-separated strings corresponding to the id attributes of the <th> elements that provide the headers for this header cell.

pub fn href(url: String) -> Attribute

Specifies the URL of a linked resource. This attribute can be used on various elements to create hyperlinks or to load resources.

pub fn hspace(value: Int) -> Attribute

Specifies horizontal whitespace in pixels on the left and right sides of an image. Legacy attribute still useful for email client compatibility.

pub fn http_equiv(value: String) -> Attribute

Sets a pragma directive for a document. This is used in meta tags to define behaviors the user agent should follow.

pub fn id(value: String) -> Attribute

The "id" attribute is used to uniquely identify a single element within a document. It can be used to reference the element in CSS with the selector #id, in JavaScript with document.getElementById("id"), or by anchors on the same page with the URL "#id".

pub fn lang(language: String) -> Attribute

Specifies the language of the element’s content and the language of any of this element’s attributes that contain text. The "lang" attribute applies to the element itself and all of its descendants, unless overridden by another "lang" attribute on a descendant element.

The value must be a valid BCP 47 language tag.

pub fn name(element_name: String) -> Attribute

Name of the element to use for form submission and in the form.elements API

pub fn none() -> Attribute

Create an empty attribute. This is not added to the DOM and not rendered when calling element.to_string, but it is useful for conditionally adding attributes to an element.

pub fn rel(value: String) -> Attribute

Specifies the relationship between the current document and the linked resource. Common values for emails include "noopener noreferrer" for external links.

pub fn role(name: String) -> Attribute
pub fn rowspan(value: Int) -> Attribute

A non-negative integer value indicating how many rows the header cell spans or extends. The default value is 1; if its value is set to 0, the header cell will extends to the end of the table grouping section, that the <th> belongs to. Values higher than 65534 are clipped at 65534.

pub fn scope(value: String) -> Attribute

The scope attribute specifies whether a header cell is a header for a row, column, or group of rows or columns. The following values are accepted:

The scope attribute is only valid on <th> elements.

pub fn span(value: Int) -> Attribute

Specifies the number of consecutive columns a <colgroup> element spans. The value must be a positive integer greater than zero.

pub fn src(url: String) -> Attribute

Specifies the URL of an image or resource to be used.

pub fn style(property: String, value: String) -> Attribute

Provide a single property name and value to be used as inline styles for the element. If either the property name or value is empty, this attribute will be ignored.

Note: Style properties that have been officially tested for email client compatibility are available in the smail/style module. It is strongly recommended to use smail/style whenever possible. This function remains available as an escape hatch for any property not covered by that module.

Note: unlike most attributes, multiple style attributes are merged with any existing other styles on an element. Styles added later in the list will override styles added earlier.

pub fn styles(properties: List(#(String, String))) -> Attribute

Provide a list of property-value pairs to be used as inline styles for the element. Empty properties or values are omitted from the final style string.

Note: Style properties that have been officially tested for email client compatibility are available in the smail/style module. It is strongly recommended to use smail/style whenever possible. This function remains available as an escape hatch for any property not covered by that module.

Note: unlike most attributes, multiple styles attributes are merged with any existing other styles on an element. Styles added later in the list will override styles added earlier.

pub fn target(value: String) -> Attribute

Specifies where to display the linked resource or where to open the link. The following values are accepted:

ValueDescription
“_self”Open in the same frame/window (default)
“_blank”Open in a new window or tab
“_parent”Open in the parent frame
“_top”Open in the full body of the window
framenameOpen in a named frame

Note: consider against using "_blank" for links to external sites as it removes user control over their browsing experience.

pub fn title(text: String) -> Attribute

Annotate an element with additional information that may be suitable as a tooltip, such as a description of a link or image.

It is not recommended to use the title attribute as a way of providing accessibility information to assistive technologies. User agents often do not expose the title attribute to keyboard-only users or touch devices, for example.

pub fn type_(control_type: String) -> Attribute

Type of element

pub fn value(control_value: String) -> Attribute

Specifies the value of an element.

pub fn vspace(value: Int) -> Attribute

Specifies vertical whitespace in pixels on the top and bottom sides of an image. Legacy attribute still useful for email client compatibility.

Search Document