China may be the planet's biggest polluter but it's also powering ahead of other countries on renewable energy.

As the Trump administration yanks the U.S. out of the Paris climate change agreement, claiming it will hurt the American economy, Beijing is investing hundreds of billions of dollars and creating millions of jobs in clean power.

China has built vast solar and wind farms, helping fuel the growth of major industries that sell their products around the world.

Related: Trump's renewable energy cuts alarm former officials

"Even in China where coal is -- or was -- king, the government still recognizes that the economic opportunities of the future are going to be in clean energy," said Alvin Lin, Beijing-based climate and energy policy director with the Natural Resources Defense Council.

More than 2.5 million people work in the solar power sector alone in China, compared with 260,000 people in the U.S., according to the most recent annual report from the International Renewable Energy Agency.

While President Trump promises to put American coal miners back to work, China is moving in the opposite direction.

Related: There is no boom in coal jobs

Coal still makes up the largest part of China's energy consumption, but Beijing has been shutting coal mines and set out plans last year to cut roughly 1.3 million jobs in the industry. The Chinese government has also moved to restrict the construction of new coal power plants.

For the first time ever, China's National Energy Administration in January established a mandatory target to reduce coal energy consumption. It also set a goal for clean energy to meet 20% of China's energy needs by 2030.

Analysts expect China to easily meet that target. Greenpeace noted in a report earlier this year that the country's clean energy consumption rose to 12% at the end of 2015. Renewable energy sources account for about 10% of total U.S. energy consumption, according to official statistics.

Related: Trump suggests border wall with solar panels

To help reach the 2030 goal, China is betting big on renewable energy. It pledged in January to invest 2.5 trillion yuan ($367 billion) in renewable power generation -- solar, wind, hydro and nuclear -- by 2020.

The investment will create about 10 million jobs in the sector, the National Energy Administration projects. China currently boasts 3.5 million jobs in clean energy, by far the most in the world, according to the International Renewable Energy Agency.

The country has already become a major manufacturer and exporter of renewable energy technology, supplying some two-thirds of the world's solar panels.

China also has a strong grip on wind power. It produces nearly half of the world's wind turbines -- at a rate of about two every hour.

China's hottest new project is a giant floating solar energy farm located in the eastern province of Anhui.

Covering about 100 square miles, it is the largest floating panel facility in the world. It has the capacity to produce enough energy to power 15,000 homes, according to Sungrow Power Supply, the company behind the farm.

Fittingly, the solar farm floats atop a flooded area once home to a coal mining factory.

The idea to float solar panels is fast catching on in an industry that faces one persistent problem -- space.

"The government won't allow us to just install panels wherever we want," says Yao Shaohua, the deputy director of the project. "This lake wouldn't be used otherwise, so it makes sense."

Related: Why Apple is investing in wind turbines in China

Initially it is more expensive to build solar farms on water than on the land. But experts say floating solar panels can run more efficiently in the long run, because they are cooled by the water underneath.

"The whole world, including China, is recognizing that we need to fight climate change," said Yao. "I'm pretty sure this is going to be a trend."

China's growing dominance in the sector has had a huge effect on the global market.

Manufacturers dramatically ramped up production of solar panels, driven by an estimated $42 billion in government subsidized loans between 2010 and 2012, according to the GW Solar Institute at George Washington University. The flood of Chinese panels was one of the main reasons why world prices crashed by 80% between 2008 and 2013.

Related: Trump and China could still fall out badly over trade

The U.S. accused China of flooding the market and the Commerce Department started imposing steep tariffs on Chinese-made solar panels in 2012 in a bid to protect American producers.

Just last month, the U.S. informed the World Trade Organization that it may impose tariffs on imports of solar panels from other countries as well, alleging that Chinese companies have opened production facilities in third countries to get around import restrictions.