It isn't illegal but it is unwise. Some girls under 18 have claimed that their sex was not consensual when they got mad at the guy which has caused him all sorts of problems with the law--in fact, the law says a girl or boy under 18 is not capable of giving consent.
a person under 18 is not considered to be able to make an adult decision. meaning if an adult trys to date you, he is considered to be taking advantage of a child. once you add sex to the equation, then you start to enter the truly illegal stuff.
states have different laws regarding this matter you could look up the statute for your state to be sure but remember if he is 18 and you are not your parents can still get a restraining order against him because you are a minor, so no its not necessarily illegal