Creating UI elements on runtime?

I want to know how to create a UI element like Button or a Slider by code
Just like we do it with the Editor by clicking RMB on hierarchy and selecting the “UI” category, but with code

you can have a ui button as prefab and then runtime you can instantiate and setup image and size

same thing you can do with slider also .