Search code examples
cssimagesrc

Is it possible to change img src attribute using css?


I'm trying to change img src (not the background img src) with css

<img id="btnUp" src="img/btnUp.png" alt="btnUp"/>  

#btnUp{
    cursor:pointer;
}
#btnUp:hover{
    src:img/btnUpHover; /* is this possible ? It would be so elegant way.*/
}

Solution

  • No - CSS can only be used to change CSS background images, not HTML content.

    In general UI elements (not content) should be rendered using CSS backgrounds anyway. Swapping classes can swap background images.