An immigration bill being written in the Senate aims to wipe out nearly all illegal crossings along the southwestern border with Mexico.

It will maintain a 13-year timetable for existing illegal residents to win citizenship.

The carefully crafted language is intended to attract Republican support in Congress for comprehensive immigration legislation this year.

There are an estimated 11 million foreigners living in the US illegally. 

The idea is to create tough law-and-order provisions that backers could argue would finally fix a porous US border.

It is also thought that it would keep foreigners who have obtained visas from overstaying them.

A bipartisan group of eight Democratic and Republican senators writing the bill is hoping to sign off on the measure in coming days.

The Department of Homeland Security would be tasked with developing plans to stop nearly all illegal border crossings, two sources familiar with the plan said.

Border security would be linked to the path to citizenship and the standards would be set by Congress.

Once the group submits the plan, the US government would be allowed to start providing initial provisional legal status to the illegal immigrants who qualify.

The agency would be given $3bn (€2.2bn) to immediately implement the plan, according to one Senate aide familiar with the legislation.

The two sources, who asked not to be identified, said the DHS border plan would have a goal of stopping 90% of illegal border crossings at "high risk" areas.

If the agency failed to meet the goal in any of the first five years after the immigration law was enacted, a newly created commission would come up with additional steps to stop visa overstays and illegal border crossings, the sources said.

The federal government would dedicate another $2bn (€1.5bn) to achieve these security steps, the Senate aide said.

In addition, $1.5bn (€1.1bn) in new funding would be dedicated to additional border fence construction, making for a total of $6.5bn (€4.9bn) in new security spending.

In order for the 11 million illegal immigrants to transition from the provisional legal status to permanent residency, a number of other requirements would have to be met.

The other requirements would include more fencing on the border and a mandatory employment verification system known as e-verify.

The Senate aide familiar with the legislation said if the 90% goal is unfulfilled after ten years, undocumented residents who qualify would still be allowed to apply for "green cards," the open-ended visas that are widely seen as the gateway to US citizenship for foreigners.