Yes, you can have sex while you are having your period. However, sex during your period does not eliminate the chance of becoming pregnant. Sperm can live in the female reproductive system for up to 3 days, meaning that if you have sex near the end of your period and ovulate in the next few days, the sperm could still fertilize the egg.
This is because ovulation can cause bleeding, which tends to be lighter than a period. If you are concerned about getting pregnant, using a reliable form of contraception such as condoms or hormonal birth control is always recommended.