The government will be able to monitor the calls, emails, texts and website visits of everyone in the UK under new legislation set to be announced soon.

Internet firms will be required to give intelligence agency GCHQ access to communications on demand, in real time.

The Home Office says the move is key to tackling crime and terrorism, but civil liberties groups have criticised it.

Tory MP David Davis called it "an unnecessary extension of the ability of the state to snoop on ordinary people".

Attempts by the last Labour government to take similar steps failed after huge opposition, including from the Tories.

'Unprecedented step'

A new law - which may be announced in the forthcoming Queen's Speech in May - would not allow GCHQ to access the content of emails, calls or messages without a warrant.

But it would enable intelligence officers to identify who an individual or group is in contact with, how often and for how long. They would also be able to see which websites someone had visited.

In a statement, the Home Office said action was needed to "maintain the continued availability of communications data as technology changes".

The government will be able to get at it with no by or leave from anybodyDavid Davis, Conservative MP and former shadow home secretary

"It is vital that police and security services are able to obtain communications data in certain circumstances to investigate serious crime and terrorism and to protect the public," a spokesman said.

"As set out in the Strategic Defence and Security Review we will legislate as soon as parliamentary time allows to ensure that the use of communications data is compatible with the government's approach to civil liberties."

But Conservative MP and former shadow home secretary David Davis said it would make it easier for the government "to eavesdrop on vast numbers of people".

"What this is talking about doing is not focusing on terrorists or criminals, it's absolutely everybody's emails, phone calls, web access..." he told the BBC.

"All that's got to be recorded for two years and the government will be able to get at it with no by your leave from anybody."

He said that until now anyone wishing to monitor communications had been required to gain permission from a magistrate.

"You shouldn't go beyond that in a decent civilised society, but that's what's being proposed."

'Attack on privacy'

Nick Pickles, director of the Big Brother Watch campaign group, called the move "an unprecedented step that will see Britain adopt the same kind of surveillance seen in China and Iran".

It is a pretty drastic step in a democracyShami Chakrabarti, Liberty

"This is an absolute attack on privacy online and it is far from clear this will actually improve public safety, while adding significant costs to internet businesses," he said.

Shami Chakrabarti, director of Liberty, added: "This is more ambitious than anything that has been done before. It is a pretty drastic step in a democracy."

The Internet Service Providers Association said any change in the law must be "proportionate, respect freedom of expression and the privacy of users".

TheSunday Times quotedan industry official who warned it would be "expensive, intrusive [and] a nightmare to run legally".

Even if the move is announced in the Queen's Speech, any new law would still have to make it through Parliament, potentially in the face of opposition in both the Commons and the Lords.

The previous Labour government attempted to introduce a central, government-run database of everyone's phone calls and emails, but eventually dropped the bid after widespread anger.

The then Home Secretary Jacqui Smith did pursue efforts similar to those being revisited now, but the Conservatives and Liberal Democrats continued to voice their concerns.

The shadow home secretary at the time, Chris Grayling, said the government had "built a culture of surveillance which goes far beyond counter terrorism and serious crime".

Chris Huhne, then the Lib Dem home affairs spokesman, said any legislation requiring communications providers to keep records of contact would need "strong safeguards on access", and "a careful balance" would have to be struck "between investigative powers and the right to privacy".