Well, if you go from the Stockholm area you go through Nynäshamn to Gotland. You can take different kind of ferries to Visby. Now they a have a ferry which only takes four hours. They have a parking place very close to the harbour.
Although not a huge town, there is a good bus service, which operates all around the town, and surrounding area. Buses are red, and there are stops on most of the main streets. Timetables are displayed on the stops, and printed timetable booklets are available on the buses themselves, just behind the driver. A single journey will cost you 20kr, there are no return fares. You may travel on as many buses as you wish up until an hour after the time stamped on your ticket. Discount tickets for 60kr or 110kr may also be purchased, but not all bus drivers have them. If you have a baby in a pushchair, you will travel free of charge, and should get on the bus in the middle, rather than the front. When you want to get off, ring the bell, and the driver will stop at the next bus stop.
Trains go from Stockholm Centralen at least each hour - at 10.52, 11.52 etc, sometimes twice an hour at peak times. The cost is 60kr, or less with a discount ticket of 60kr or 110kr. The journey takes roughly an hour. Be prepared for delays or cancellations, especially in the winter. If a ferry is in port, the train will go an extra stop, but it is literally only a few minutes walk if it doesn't.
Local trains Stockholm - Nynäshamn will take a bit more than 1 hour.
If you buy the tourist travel card for Stockholm it will be valid to go here on the train and on all local buses.