SACRAMENTO — Long a leader and trendsetter in its clean-energy goals, California took a giant step on Wednesday, becoming the first state to require all new homes to have solar power.

The new requirement, to take effect in two years, brings solar power into the mainstream in a way it has never been until now. It will add thousands of dollars to the cost of home when a shortage of affordable housing is one of California’s most pressing issues.

That made the relative ease of its approval — in a unanimous vote by the five-member California Energy Commission before a standing-room crowd, with little debate — all the more remarkable.

State officials and clean-energy advocates say the extra cost to home buyers will be more than made up in lower energy bills. That prospect has won over even the construction industry, which has embraced solar capability as a selling point.