As I've understood, its not allowed to work off campus on F-1 visa. However what about online freelance work, for example something on fiverr or some other freelance website? Is that against the law too? I couldn't find information related to it.
It is prohibited. "Off-campus" refers to the identity of the employer, not to your physical location. Freelance work would be for an employer who is not affiliated with your university, so it would not meet the requirements of your F-1 status.
A commenter raises the question of doing freelance work for a client outside the US. The US position is that if the worker is physically in the US when the work is performed then US work authorization is required. It does not matter whether the non-university client or employer is in the US or outside of it; such work is a violation of status.
Apparently it’s allowed. What the law, specifically 8 CFR 214.1(e), prohibits, is employment. Employment, according to 8 CFR 274(a)(1)(h), is something only employees do. An independent contractor is not an employee (Id., (j) and (f)).
Or maybe not, according to a Connecticut Law Tribune article which says “A B-1 visitor cannot engage in productive employment in the U.S. either as an employee or as an independent contractor” (without, however, citing any laws, which do not appear to say anything about nonimmigrant independent contractors; whatever reasoning they had likely applies to F-1 as well).