DEV Community

Cover image for The Solar System in CSS

The Solar System in CSS

Mads Stoumann on August 25, 2024

The Solar System has been done in CSS a lot of times — just search Codepen! So why do it again? Because things get better and simpler — and we can...
Collapse
 
charlesr1971 profile image
Charles Robertson •

Can you give us the link to the final codepen?

Collapse
 
madsstoumann profile image
Mads Stoumann • • Edited

It’s the embedded Pen, I didn’t upload a Pen with the AU-version.

Collapse
 
charlesr1971 profile image
Charles Robertson •

Hmmm. It’s just that there is no rotation, around the sun, in the embedded pen.
The planets are only rotating around their centres.
But maybe that’s because I am viewing it via mobile Safari on an iPhone 8+ [iOS 16.7]

Thread Thread
 
madsstoumann profile image
Mads Stoumann • • Edited

Yes, offset-path was added to mobile Safari in iOS 17 😟

Thread Thread
 
charlesr1971 profile image
Charles Robertson •

Well it works on my iPhone here:

developer.mozilla.org/en-US/docs/W...

So, it must be something else?

Thread Thread
 
madsstoumann profile image
Mads Stoumann •

Not sure? offset-distance, maybe?

Collapse
 
the_riz profile image
Rich Winter •

It's great that you're providing the defaults in case a browser doesn't understand CSS variables, but I don't that any browser that has that problem would understand cqi. (I could be wrong, but I would think cqi to be to "new')

Collapse
 
madsstoumann profile image
Mads Stoumann •

Supported in all browsers:
caniuse.com/css-container-query-units

Collapse
 
ed1nh0 profile image
Edson Jr. •

As for learning purpose this article is awesome! Thank you! 👏🏼👏🏼👏🏼👏🏼👏🏼

Collapse
 
madsstoumann profile image
Mads Stoumann •

Happy to hear that — thank you!

Collapse
 
codycodes profile image
Cody Antonio Gagnon •

Awesome animation and nice use of ChatGPT for the orbits!

Collapse
 
madsstoumann profile image
Mads Stoumann •

Thanks!

Collapse
 
shikkaba profile image
Me •

What is cqi?

Collapse
 
madsstoumann profile image
Mads Stoumann •

It’s a container-query (the “cq”) unit, for the inline (“i”) dimension. If you use contanter-type: inline-size, then 100cqi is the total width of the container.

Collapse
 
shikkaba profile image
Me •

Thank you!

Thread Thread
 
link2twenty profile image
Andrew Bone •

Further reading if you're interested

developer.mozilla.org/en-US/docs/W...

Collapse
 
muhyilmaz profile image
MUHAMMED YILMAZ •

PLUTON!?

Collapse
 
madsstoumann profile image
Mads Stoumann •

It’s not a planet anymore 🤓

Collapse
 
muhyilmaz profile image
MUHAMMED YILMAZ •

no it is :I

Collapse
 
graham_mcmahon_653954877c profile image
Graham McMahon •

Not bad, but Jupiter is too small relative to Saturn, Uranus and Neptune

Collapse
 
the_riz profile image
Rich Winter •

Well, ditto the sun. And where's the Jupiter spot? And where is the Saturn ring, and, and, and...

Collapse
 
madsstoumann profile image
Mads Stoumann • • Edited

I know, see the Update 😉

Collapse
 
madsstoumann profile image
Mads Stoumann • • Edited

I know, see the Update 😉

Collapse
 
greenersoft profile image
GreenerSoft •

Bravo, that's really cool.

Collapse
 
madsstoumann profile image
Mads Stoumann •

Thanks!

Collapse
 
eyuel_3256 profile image
Tajebe Liyew •

Wow

Collapse
 
madsstoumann profile image
Mads Stoumann •

Thanks!

Collapse
 
mayowakalejaiye profile image
mayowa-kalejaiye •

Brilliant

Collapse
 
madsstoumann profile image
Mads Stoumann •

Thanks!!

Collapse
 
machineno15 profile image
Tanvir Shaikh •

This is amazing & very cool.

Collapse
 
madsstoumann profile image
Mads Stoumann •

Thank you!

Collapse
 
charlesr1971 profile image
Charles Robertson •

Here is my effort from a few years ago, using GSAP & CSS:

codepen.io/charles1971/pen/BaNyqYE

It is only the inner planets 🙂

Collapse
 
madsstoumann profile image
Mads Stoumann •

Nice!

Collapse
 
madeofclay profile image
Adam •

2d version == Flatlands! Or… flat spaces?

Though I will say, toy projects/demos like this are one of the times where using id selectors makes sense, imo. Same net result.

Great stuff!

Collapse
 
madsstoumann profile image
Mads Stoumann •

Thanks!

Collapse
 
syedmuhammadaliraza profile image
Syed Muhammad Ali Raza •

✅

Collapse
 
king_triton profile image
King Triton •

This CSS Solar System demo showcases how simple techniques can create a visually appealing model. Leveraging grid and offset-path is a clever way to achieve smooth animations and responsive design.

Collapse
 
madsstoumann profile image
Mads Stoumann •

Thank you!

Collapse
 
agunechemba profile image
Agunechemba Ekene •

Nice project for my learners!

Collapse
 
madsstoumann profile image
Mads Stoumann •

Great!

Collapse
 
arseytech profile image
Arsey Kun •

Mindfully blown, wow. Animators are.....
A way

Collapse
 
madsstoumann profile image
Mads Stoumann •

Cool, thanks!

Collapse
 
beatrice_wambui profile image
Beatrice Wambui Mbugua •

This is really cool

Collapse
 
madsstoumann profile image
Mads Stoumann •

Thanks!

Collapse
 
nora_2b5ca57f338a479bcc91 profile image
Nora •

I especially like how the animation is handled with offset-path, keeping the movement smooth and intuitive. I also created my website using html and css. give it a view and share your suggestions where it needs improvement.