a sliding mechanism for portable electronic device includes a sliding housing , a main housing and a stopping module . the sliding housing includes two ledges . at least one of the ledges defines a first notch and a second notch . the main housing includes two rails and at least one elastic member . the sliding housing is slidingly attached to the main housing by engagement of the ledges and the rails . the at least one elastic member includes a positioning portion . the positioning portion flexibly resists the at least one of the ledges and is selectively engaged in the first notch and the second notch . the stopping module prevents the sliding housing from separating from the main housing .