The Charity Commission said political activity should be in support of a charity's aims and proportionate, with transparency about funding sources.
It has warned charity trustees of the "reputational risk" of getting involved in the EU referendum campaign.
The commission said it would take action against any rule breaches.
The in-out referendum on Britain's membership of the EU will take place on 23 June.
The guidance said: "Many charities are funded by the EU or its institutions, and conditions are usually attached to the funding.
"For charities that are in direct receipt of such funding, the possibility of a loss of funding will clearly be an issue.
"However, knowing that the outcome of the referendum could result in a loss of funding would not in itself justify political activity directed at the UK remaining in the EU."
The commission said the key issue should be whether staying in, or leaving, the EU would affect an organisation's "charitable purposes and the ability of your charity to continue its work", and that the extent of engagement "must be proportionate to the issue involved".
"Trustees must consider issues such as the risk posed to the charity by the loss of funding and the ability to replace the funding that is at risk of being lost," it added.
The commission said charities that choose to get politically involved in the referendum should be transparent about their sources of funding.
Failure to do so, it said, "could seriously undermine and detract from the quality of your contribution to these very important issues and may attract regulatory scrutiny by the commission".
Kenneth Dibble, the commission's director of legal services, added: "Political activity by a charity can only ever be undertaken in support of its charitable purposes.
"The guidance clearly says that there are reputational risks for charities which engage in political activity on the EU referendum."
UK charities in receipt of EU funds should not campaign for a vote to stay in the EU solely because of potential losses in income, new guidance says.