Search code examples
htmlimageclasselmsrc

How do I add src and class to a Html.img in Elm?


I have an Html.img in Elm and I would like to add src and a class to it. How do I do that? Thanks!


Solution

  • import Html exposing (img, div)
    import Html.Attributes exposing (class, src)
    
    
    view : Model -> Html Msg
    view model =
        div []
            [ img [ class "my-img", src "https://loremflickr.com/320/240" ] []
            ]
    

    View a live example here!

    Or read more about Html.Attributes.