We present a novel autoencoder-based approach for designing codes that provide unequal error protection (UEP) capabilities. The proposed design is based on a generalization of an autoencoder loss function that accommodates both message-wise and bit-wise UEP scenarios. In both scenarios, the generalized loss function can be adjusted using an associated weight vector to trade off error probabilities corresponding to different importance classes. For message-wise UEP, we compare the proposed autoencoder-based UEP codes with a union of random coset codes. For bit-wise UEP, the proposed codes are compared with UEP rateless spinal codes and the superposition of random Gaussian codes. In all cases, the autoencoder-based codes show superior performance while providing design simplicity and flexibility in trading off error protection among different importance classes.