We present a novel autoencoder-based approach for designing codes that provide unequal error protection (UEP) capabilities. The proposed approach, based on a generalization of an autoencoder loss function, provides a versatile framework for the design of message-wise and bit-wise UEP codes. Using an associated weight vector, the generalized loss function can be used to trade off error probabilities corresponding to different importance classes and to explore the region of achievable error probabilities. 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.