A bed includes a base, a mattress-supporting device, two driving units and a limiting unit. The base includes two tracks. The mattress-supporting device includes a frame, a body-supporting element and a leg-supporting element. The frame includes rollers supported on the tracks. The body-supporting element is pivotally connected to an end of the frame. The leg-supporting element is pivotally connected to another end of the frame. The first driving unit is operable for pivoting the body-supporting element. The second driving unit is operable for pivoting the leg-supporting element. The limiting unit is movable between a first position to allow horizontal movement of the mattress-supporting device on the base as the body-supporting element is pivoted and a second position to avoid horizontal movement of the mattress-supporting device on the base as the body-supporting element is pivoted.