How to create a gradient material across an object's local z-axis?
Depending on what you’re looking for, you could get away with using Generated coordinates, which are normalized relative to the object’s bounding box: