Understanding the self-assembly and hybridization properties of DNA oligonucleotides in confined spaces can help to improve their applications in biotechnology and nanotechnology. This study investigates the effects of spatial confinement in the pores of hydrogels on the thermal stability of DNA oligonucleotide structures. The preparation of oligonucleotides embedded in agarose gels was simple, whereas the preparation of oligonucleotides embedded in polyacrylamide gels was required to remove unpolymerized monomers. In the latter case, a method for rehydrating a washed dry gel with a buffer solution containing oligonucleotides was developed. Fluorescence measurements of oligonucleotides bearing fluorescent probes revealed no significant influence of the internal environment of the gel pores on the stability of DNA duplex, hairpin, and G-quadruplex structures. Moreover, the effects of poly(ethylene glycol) on the stability of DNA structures in the gels were similar to those in solutions. It is likely that the oligonucleotides are not strongly constrained in the gels and may be preferentially located in a water-rich environment in the gel matrix. The gel preparation was also applied to the assessment of the stability of DNA structures under the conditions of a reduced number of water molecules. The studies using hydrogels provide insights into the ability of self-assembly and hybridization of oligonucleotides in confined environments and under low-water-content conditions.