Background: Excessive utilization of electronic media may affect the individuals' health and quality of sleep. This study aimed to investigate sleep quality of the college students based on their diets and duration of time spent on the internet. Methods: In this cross-sectional web-based study, 385 students were selected randomly from the Qazvin University. Data was collected by a self-administered online questionnaire designed in Google-drive. The questionnaire included demographic information, Petersburg sleep quality, duration of time spent on the internet, food habit, health status, physical activity, and anthropometric characteristics. A total of 229 students filled out the questionnaire completely. To analyze the data, SPSS version 22 was used. Paired t-test, ANOVA, ANCOVA, and Pearson correlation coefficient were applied for statistical analyses. Results: The mean time spent on the internet was 28.83 ± 20.89 hours/week, which showed a significant relationship with the students' health status (P = 0.005), sleep quality score (P = 0.048), components of sleep quality (P = 0.029), and sleep disorder (P = 0.01). The mean score of Petersburg sleep quality index demonstrated a significant relationship with marital status (P = 0.029), Body mass index (P = 0.008), as well as consumption of some food groups like fruits, sausage and salami, and canned foods (P = 0.048, 0.05, 0.01). Conclusions: Students who used the internet a lot had poor-quality sleep and unhealthy food choices. This was a reciprocal relation. Consequently, a healthier life style and minimum duration of time on the Internet can lead to physical health and better quality asleep.