This paper proposes a supervised sparsity-based wavelet feature (SSWF) for the detection of bearing fault, which combines wavelet packet transform (WPT) and sparse coding. SSWF is extracted from vibration signals by four main steps: (1) construct a WPT vector using the fault-related WPT coefficients; (2) design a structured dictionary that combines the signal characteristics and class information; (3) use the dictionary to implement the sparse coding of the WPT vectors, which can be solved by basis pursuit (BP) and (4) calculate the SSWF from the sparse coefficients. During the process, WPT can detect the fault occurrence of the bearing signal. Sparse coding based on a structured dictionary can find a robust representation of the signal and at the same time, integrate the class information. Therefore, SSWF is able to stably and discriminatively reflect different fault types, which indicates its potential in bearing fault diagnosis. Experiments on two bearing cases are conducted to verify the advantages of SSWF in the detection of bearing faults.