MackeyRMS/elm-ui/1.0.5

NOTE: the latest version is 2.0.3

Element.Font

import Element
import Element.Font as Font


view =
    Element.el
        [ Font.color (Element.rgb 0 0 1)
        , Font.size 18
        , Font.family
            [ Font.typeface "Open Sans"
            , Font.sansSerif
            ]
        ]
        (Element.text "Woohoo, I'm stylish text")

Note: Font.color, Font.size, and Font.family are inherited, meaning you can set them at the top of your view and all subsequent nodes will have that value.

Other Note: If you're looking for something like line-height, it's handled by Element.spacing on a paragraph.

color : Color -> Attr decorative msg
size : Int -> Attr decorative msg

Font sizes are always given as px.

Typefaces

family : List Font -> Attribute msg
import Element
import Element.Font as Font


myElement =
    Element.el
        [ Font.family
            [ Font.typeface "Helvetica"
            , Font.sansSerif
            ]
        ]
        (text "")
type alias Font =
Font
typeface : String -> Font
serif : Font
sansSerif : Font
monospace : Font
{ url : String
, name : String
}
-> Font

Note it's likely that Font.external will cause a flash on your page on loading.

To bypass this, import your fonts using a separate stylesheet and just use Font.typeface.

It's likely that Font.external will be removed or redesigned in the future to avoid the flashing.

Font.external can be used to import font files. Let's say you found a neat font on http://fonts.google.com:

import Element
import Element.Font as Font


view =
    Element.el
        [ Font.family
            [ Font.external
                { name = "Roboto"
                , url = "https://fonts.googleapis.com/css?family=Roboto"
                }
            , Font.sansSerif
            ]
        ]
        (Element.text "Woohoo, I'm stylish text")

Alignment and Spacing

alignLeft : Attribute msg

Align the font to the left.

alignRight : Attribute msg

Align the font to the right.

center : Attribute msg

Center align the font.

justify : Attribute msg
letterSpacing : Float -> Attribute msg

In px.

wordSpacing : Float -> Attribute msg

In px.

Font Styles

underline : Attribute msg
strike : Attribute msg
italic : Attribute msg
unitalicized : Attribute msg

This will reset bold and italic.

Font Weight

heavy : Attribute msg
extraBold : Attribute msg
bold : Attribute msg
semiBold : Attribute msg
medium : Attribute msg
regular : Attribute msg
light : Attribute msg
extraLight : Attribute msg
hairline : Attribute msg

Variants

type alias Variant =
Variant
variant : Variant -> Attribute msg

You can use this to set a single variant on an element itself such as:

el
    [ Font.variant Font.smallCaps
    ]
    (text "rendered with smallCaps")

Note These will not stack. If you want multiple variants, you should use Font.variantList.

variantList : List Variant -> Attribute msg
smallCaps : Variant

Small caps are rendered using uppercase glyphs, but at the size of lowercase glyphs.

slashedZero : Variant

Add a slash when rendering 0

ligatures : Variant
ordinal : Variant

Oridinal markers like 1st and 2nd will receive special glyphs.

tabularNumbers : Variant

Number figures will each take up the same space, allowing them to be easily aligned, such as in tables.

Render fractions with the numerator stacked on top of the denominator.

Render fractions

swash : Int -> Variant
feature : String -> Bool -> Variant

Set a feature by name and whether it should be on or off.

Feature names are four-letter names as defined in the OpenType specification.

indexed : String -> Int -> Variant

A font variant might have multiple versions within the font.

In these cases we need to specify the index of the version we want.

Shadows

glow : Color -> Float -> Attr decorative msg

A glow is just a simplified shadow.

{ offset : ( Float, Float )
, blur : Float
, color : Color
}
-> Attr decorative msg