burger menu icon
WillMaster

WillMaster > LibraryWeb Page and Site Features

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

CSS Rotate

When you wish to rotate text or an image, consult this article for a basic how-to. Only HTML and CSS are used. No JavaScript is required for this functionality.

Here are 4 examples. The word "Rotation" is being rotated in 2 of the examples. The Willmaster logo is being rotated in the other two examples.

(If the examples don't rotate in your email reader, see the online article.)
2-second Rotation
Rotation
4-second Rotation
Rotation
9-second Rotation
Willmaster logo
0.65-second Rotation
Willmaster logo

The rotation rate is specified in the CSS. Here is the CSS. The rotation is specified in the last line of CSS code (marked as 2s for visual recognition).

<style type="text/css">
@keyframes rotating {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
.rotation-div { animation: rotating 2s linear infinite; }
</style>

The CSS can be used as you see it above. You may change 2 in 2s and you may also change rotation-div in the CSS.

The digit 2 in 2s specifies the number of seconds to use for one rotation. The s in 2s confirms that you mean number of seconds.

Change 2s according to how fast you want your text or image to rotate.

The rotation-div is the class name to use in your HTML. The rotation-div class name may changed. If changed, the class name in the following HTML example will need to be changed accordingly.

These two div tag examples rotate the word "Rotation" and rotate the Willmaster logo.

<div 
  class="rotation-div"
  style="text-align:center; width:100px; height:100px; line-height:100px;" 
>Rotation</div>

<div 
  class="rotation-div"
  style="width:50px; height:50px;" 
><img src="https://www.willmaster.com/images/wmlogo_icon.png" style="width:50px; height:50px;" alt="Willmaster logo"></div>

Notice in both div tags that rotation-div is the class name.

Each div has its own styling in addition to the rotation-div class.

The rotating text:

The div style's height value is the same as the width value.

The line-height value is the same as the height value. It brings the rotating text down to the vertical middle of the div.

The text-align:center CSS centers the text horizontally within the div.

The above CSS is for one line of text within the rotating div. If you need more than one line, let me suggest creating an image with the text and rotating the image. Otherwise, you'll need to put a div within the rotating div and futz with the CSS until the rotation is what you want to see.

The rotating image:

The div style's height value and width value are the same as the image's height value and width value.

That was the basic code for rotating a line of text or an image.

(This content first appeared in Possibilities newsletter.)

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2025 Will Bontrager Software LLC