DENVER — With a stroke of the governor’s pen, Colorado on Thursday legalized civil unions for same-sex couples, a major shift for a Western state where voters outlawed same-sex marriages in 2006.

The law makes Colorado the 18th state to allow gay marriage or some form of same-sex union, and its signing comes days before the Supreme Court hears two major cases on marriage equality.

For many gay Coloradans, it was a jubilant — if almost unreal — moment.

“When we started fighting for it, this was a foregone conclusion that it wasn’t going to happen,” said Jerry Cunningham, the publisher of the magazine Out Front Colorado. “It’s kind of amazing. It’s creating an awareness that we can have relationships. It validates it and legitimizes it, and says it’s O.K.”

Across Colorado, couples are already making plans. Denver’s fourth annual gay and lesbian wedding expo is being held at the end of April (“Begin planning your own dream civil union!”) and the county clerks in Denver and Boulder are planning to open their offices at midnight on May 1 — when the law takes effect — to hand out the first civil union licenses.