I have two images: one for small width and the other for big. I've tried this code but it is not working:
<img src="small.jpg" srcset="big.jpg 401w" alt="xx">
I think this should be a CSS topic and not a php.
You might be missing the rest of the code since all you posted was one line.
You need to to tell the browser when you want the img to change sizes. In the code below it changes at 400px;
<picture>
<source srcset="small.jpg" media="(max-width: 400px)">
<source srcset="big.jpg">
<img src="big.jpg" alt="Flowers" style="width:auto;">
</picture>
source W3c website.