Website Pricing Guide

Enter your email to get instant access to our website pricing guide.

Getting To Know The CSS Transform Property

June 12, 2024 by
You’ve written the HTML, your CSS seems just right, and your web page looks great. But something’s missing. You want your website to feel alive, to really pop. That’s where CSS transform comes in. This powerful feature lets you move, resize, rotate, and even skew elements on your page. It’s like adding a little magic, […]


You’ve written the HTML, your CSS seems just right, and your web page looks great. But something’s missing. You want your website to feel alive, to really pop.

That’s where CSS transform comes in.

This powerful feature lets you move, resize, rotate, and even skew elements on your page. It’s like adding a little magic, making your designs feel interactive and dynamic.

Think of websites where you may have seen images that tilt when you hover over them, a zoom-in effect to get a closer look at something, or an icon on a button that moves when you hover over it.

That’s CSS transforms working behind the scenes.

It’s a simple property that can completely change how users interact with your website. In this guide, we’ll learn how to create interactive visual effects that will make your website stand out from the crowd.

Let’s dive in!

Understanding The Basics Of CSS Transform

Before jumping into CSS transform, you need to have a solid CSS foundation. If you don’t already know CSS, check out our blog post on learning CSS.

Now, let’s move right into CSS transforms. CSS transforms let you visually manipulate an element.

Think rotating, scaling, skewing, or moving it around. These changes happen in a 2D or 3D space giving you lots of creative freedom.

Here’s what adding a simple CSS transform to an element looks like:

An Example Of A Simple Css Transform To An Element
Getting To Know The Css Transform Property 41

Here:

  • .element is the selector for the element you’re transforming.
  • function(value) tells you the specific transformation and how much of it you want.

The transform property supports multiple functions, which can be combined to create complex 2D and 3D transformations.

Let’s explore some of them, shall we?

Exploring 2D CSS Transformations

CSS transformations are really cool —- they let you manipulate how elements are displayed on a webpage. Think of it like moving stuff around in real life, but with code. Here, we’ll look at some of the 2-dimensional transformations available in CSS.

Rotating Elements

One of the most common things you can do with CSS transformations is rotate stuff. Suppose you’ve got a button that says Click Me, or any button on your website. We can use the rotate function in CSS to make it a bit more interesting.

Let’s say you have a call-to-action button on your website: Click Me. Here’s how you can use rotate() to make it stand out:

.cta-button {
  transition: transform 0.3s;
}

.cta-button:hover {
  transform: rotate(-10deg);
}

So, what are we doing here?

Css Code For Rotating The Property On The Left, And The Default Vs. Hover Designs For The &Quot;Click Me&Quot; Button On The Right.
Getting To Know The Css Transform Property 42

We’ve specified that when someone hovers their mouse over a button, it should rotate by -10 degrees.

The transition of 0.3s specifies how long an animation should take to complete. So, instead of switching to the rotated position in a jerk, it takes a little time to show the user a smooth transition from normal to the rotated state.

Scaling Elements

The scale() function allows you to create a sense of depth, emphasis, and visual hierarchy within your designs.

Let’s say you have a few customer testimonials on hand; something you’d like to show off to your website visitors.

Now, we don’t just want them sitting there flatly on the page. With a bit of CSS transform, you can make them pop when a user’s cursor hovers over them.

.testimonial-card {
  transition: transform 0.3s;
}

.testimonial-card:hover {
  transform: scale(1.1);
}
Css Transform Scale Property
Getting To Know The Css Transform Property 43

What are we doing here?

  • First, we’re targeting each testimonial container. We’ve assumed the class as testimonial-card.
  • The transition property smooths out the scaling effect over 0.3 seconds, so it feels natural. 
  • When a user hovers their mouse over a card, it subtly scales up just a bit (1.05 times its original size).

This little change grabs the user’s eye and makes that particular testimonial stand out. It’s a subtle difference on the page, but certainly a noticeable one.

Get Content Delivered Straight to Your Inbox

Subscribe now to receive all the latest updates, delivered directly to your inbox.

Skewing Elements

Skewing is a transformation that allows you to tilt elements along the X or Y axis, creating a sense of movement and dynamism.

In particular, the skew() transformation offers a way to introduce a sense of movement and dynamism to your website’s elements.

Consider a section dedicated to customer testimonials. Here’s how you can use skew() to make them stand out:

.testimonial {
  transition: transform 0.3s;
}

.testimonial:hover {
  transform: skewX(-10deg);
}

When a user hovers over a testimonial, it’ll subtly tilt along the X-axis by -10 degrees.

This slight skew, achieved through the skewX() function within the CSS transform property, adds visual interest without being overly distracting.

Css Transform Skew Property
Getting To Know The Css Transform Property 44

You’ll also notice that we consistently add the transition property specifying the time as 0.3s for an animation to complete.

Translating Or Moving Elements

Translation in web design means moving elements around a page.

Think of it like this: you’re positioning elements on a grid, and you can shift them along the X, Y, or even Z axis without changing or moving anything else.

Say you have a navigation bar on your website. You want it to subtly react when a visitor’s cursor hovers over the menu items.

With translate( ), you can make that happen. Let’s see some code to understand this better:

.menu-item {
  transition: transform 0.2s;
}

.menu-item:hover {
  transform: translateX(10px);
}

What we’ve done here is apply a simple transition effect. Now, when you hover the cursor over a .menu-item, it smoothly moves 10 pixels to the right. Cool, right?

Css Code For Translating The Property On The Left, And The Default Vs. Hover Designs For The Buttons On The Right.
Getting To Know The Css Transform Property 45

The beauty of translations is that they aren’t limited to just hover effects. You can use them to create cool entrance and exit animations for your website elements, move items relevant to specific pages when you are on that page, and much more.

Basics Of 3D CSS Transformations

We’re now familiar with moving things up, down, left, and right — that’s our typical 2D movement.

However, CSS allows you to step into the world of 3D transformations, where we can manipulate elements along the z-axis.

So, what 3D transformations does CSS offer?

  • First, the rotation functions: rotateX(angle), rotateY(angle), and rotateZ(angle). To put this in perspective, rotateZ is our spinning wheel, rotateY is a turning page, and rotateX is a coin flip. They each control the rotation around their respective axes.
  • translateZ(z) translates, or moves, an element along the z-axis. A positive value brings it closer, while a negative value pushes it further back. Think of it as adjusting the zoom on a camera, focusing on different depths.
  • The scaleZ(z) function allows you to scale an element along the z-axis. It’s like stretching or compressing an element along a single line. Values greater than 1 make it appear closer to you, while values between 0 and 1 make it recede into the background.

To create a 3D transformation effect, you need to set a perspective on the parent element. The perspective property determines the distance between the viewer and the z=0 plane, affecting how the 3D transformations are perceived.

Let’s add a few more styles, like width, height, and background color to make the transition clearer when you look at it from your screen:

.parent {
  perspective: 500px;
  width: 200px;
  height: 200px;
  margin: 100px auto;
}

.child {
  width: 200px;
  height: 200px;
  background-color: blue;
  transform: rotateY(45deg);
  transition: transform 0.5s;
}

.child:hover {
  transform: rotateY(0deg);
}

Here’s what the HTML would look like:


  
Css Code For 3D Transforms On The Left, And The Default Vs. Hover Designs For The Buttons On The Right.
Getting To Know The Css Transform Property 46

We have two divs, parent and child. The parent, our stage, has its perspective set to 500 pixels. The child, a red square, is initially rotated 45 degrees along the Y-axis using rotateY(45deg).

On hover, we use transform: rotateY(0deg) to reset the rotation, allowing it to return smoothly to its original position.

Controlling The CSS Transform Origin

By default, CSS transformations occur around the center of an element. However, you can change this point of origin using the transform-origin property. This property allows you to specify the X, Y, and Z coordinates of the point around which the transformation should occur.

The syntax for the transform-origin property is as follows:

.element { 
transform-origin: x-axis y-axis z-axis; 
}

The x-axis and y-axis values can be specified using length units (e.g., pixels), percentages, or keywords (left, center, right, top, or bottom). The z-axis value is only relevant for 3D transformations and is specified using length units.

Here’s an example that demonstrates how changing the transform-origin affects a rotation:

.box { 
transform: rotate(45deg); 
transform-origin: top left; 
}

In this case, the element will rotate 45 degrees around its top-left corner instead of its center.

Css Code Rotate Transform-Origin Property On The Left, And The Before Vs. After Designs For The Element On The Right.
Getting To Know The Css Transform Property 47

The transform-origin property gives you fine-grained control over how transformations are applied, allowing you to create more precise and visually appealing effects.

Creating Complex CSS Transform Effects By Combining Them

One of the most powerful aspects of the CSS transform property is the ability to combine multiple transformations to create complex and visually stunning effects. By chaining different transformation functions together, you can unleash your creativity and craft unique and captivating designs.

Let’s say you have a product card on your e-commerce website. When a user hovers over the card, you want it to scale up, rotate slightly, and lift off the page with a shadow effect:

.product-card {
  transition: transform 0.3s, box-shadow 0.3s;
}

.product-card:hover {
  transform: scale(1.05) rotate(5deg);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}
Code For Combining Css Transform Effects On The Left, And The Default Vs. Hover Designs For The Product Card On The Right.
Getting To Know The Css Transform Property 48

When a user hovers over the product card, it smoothly scales up to 1.05 times its original size, rotates by 5 degrees, and gains a box shadow that creates a lifted effect. The combination of scaling, rotation, and shadow creates a dynamic and engaging interaction.

Wrap-Up And Continued Learning

You’ve put in the time learning about CSS transforms: rotating, resizing, skewing, and positioning, which lets you create some sophisticated visual effects. This skill is really valuable for building websites that work well on different screens and for making your sites more visually appealing.

However, there’s even more you can do with this. If you’re interested in going further, you could look into some of these areas:

  • Using CSS to make smooth transitions and animations.
  • Exploring 3D transforms to add depth to your designs.
  • Learning how to animate SVG images for more complex effects.
  • Finding creative ways to combine transforms with other CSS properties.
  • Learn Tailwind CSS and Bootstrap CSS to make your overall page look good.

The best way to get better is to keep working with it and trying new things. That’s how you discover what’s possible and develop your own unique style.

When you start playing with CSS, you’ll likely need high-speed hosting that doesn’t bog your site down. Enter super-fast DreamHost’s shared hosting plans for all your website’s needs!

Get Content Delivered Straight to Your Inbox

Subscribe now to receive all the latest updates, delivered directly to your inbox.

Ian is a Product Designer based in Los Angeles, California. He is responsible for driving brand and product design at DreamHost, developing and maintaining our internal design system, and writing frontend code when he can. In his free time, he enjoys walking his dog, learning history, and discovering new music online and irl. Connect with him on LinkedIn: https://www.linkedin.com/in/ianhernandez23/

Your Dream Website Is Just One Click Away

At Ericks Webs Design, we believe every business deserves a stunning online presence — without the stress. We offer flexible payment options, a friendly team that truly cares, and expert support every step of the way.

Whether you’re a small business owner, a church, or a growing brand, we’re here to bring your vision to life.

✨ Let’s build something amazing together.

— no pressure, just possibilities.

Latest News & Website Design Tips

Stay up-to-date with the latest insights, trends, and tips in business website design. Explore our newest articles to discover strategies that can help you elevate your online presence and grow your business.

Commercial Real Estate Website Design That Sells

Commercial Real Estate Website Design That Sells

Elevate your online presence with effective commercial real estate website design that captivates and converts visitors. At Ericks Web Design, we help you build an engaging site that showcases properties through high-quality images, user-friendly navigation, and mobile optimization. Incorporate strong calls-to-action and SEO strategies to ensure potential clients find you easily. Including client testimonials can build trust, while fresh content keeps your site relevant. We’re here to transform your vision into a compelling selling tool. Let’s elevate your online presence in South Texas!

Why You Should Use a Lead Magnet (and What to Offer)

Why You Should Use a Lead Magnet (and What to Offer)

In today’s digital landscape, using a lead magnet is essential for small businesses looking to attract new customers. A lead magnet is a valuable offer, such as an eBook or discount, provided in exchange for contact information. This strategy not only builds relationships and increases website traffic but also helps in segmenting the audience. For South Texas businesses, effective options include free guides, checklists, or webinars tailored to local needs. Implementing a lead magnet enhances engagement and grows your online presence. Start leveraging lead magnets today to drive customer connections and elevate your web design strategy.

Keyword: lead magnet

Church Websites Built for Growing Congregations

Church Websites Built for Growing Congregations

Summary:

Church leaders in South Texas and beyond often struggle with an outdated online presence, jeopardizing community connections. A well-designed church website is essential for growth, serving as a welcoming space to engage current and potential members. Key elements include user-friendly navigation, engaging visuals, and SEO optimization to enhance visibility, ensuring newcomers can find services easily. Consistent content updates and bilingual options further foster inclusivity. Ericks Web Design specializes in creating tailored websites that reflect each congregation’s heart and community spirit, making it easier to connect and grow.

Keyword: Church websites.

How to Track Website Visitors (And What to Do With That Data)

How to Track Website Visitors (And What to Do With That Data)

Tracking website visitors is crucial for small businesses in South Texas to enhance their online presence. By using tools like Google Analytics, you can gather data on unique visitors, page views, and demographics, enabling you to tailor your content and promotions effectively. Understanding these metrics helps refine your strategy and improve user experience, ultimately driving more inquiries and sales. Leverage visitor data to create targeted ads and continuously monitor your site’s performance for ongoing success.

Keyword: website visitors tracking.

Catering Websites That Tastefully Sell Your Services

Catering Websites That Tastefully Sell Your Services

Summary:

The article "Catering Websites That Tastefully Sell Your Services" emphasizes the importance of a strong online presence for small businesses in South Texas. It highlights that a well-designed website acts as a business card, showcasing a brand’s personality and engaging customers with relatable content. Quality visuals and effective SEO strategies are key to attracting visitors. The piece encourages business owners to maintain an inviting atmosphere online, ultimately creating a memorable experience. Ericks Web Design offers services to help businesses build stylish and effective websites, ensuring they thrive in the digital space.

Keyword: Catering Websites

Top Email Marketing Tools to Connect With Visitors

Top Email Marketing Tools to Connect With Visitors

Summary:

For South Texas business owners, effective email marketing is a key strategy to connect with visitors and boost sales. This article highlights top tools like Mailchimp, Constant Contact, SendinBlue, and HubSpot, each offering unique features tailored for local businesses. Email marketing ensures direct access to customers, cost-effectiveness, and personalization, making it a vital component of digital marketing. Invest in these tools to enhance engagement and strengthen customer relationships.

Keyword: Email marketing tools

Carpet Cleaning Websites That Look Spotless

Carpet Cleaning Websites That Look Spotless

Summary:

To enhance your carpet cleaning business’s online visibility, a polished website is essential. A clean, professional design with strong branding and mobile optimization fosters trust and attracts customers. SEO strategies, including proper keywords and quality content, are vital for effective engagement. Regular website maintenance ensures your online presence remains fresh and functional. By prioritizing these elements, you’ll transform your website into a standout asset, much like a freshly cleaned carpet. For assistance, Ericks Web Design offers tailored solutions for businesses in McAllen, TX, and beyond.

Keyword: Carpet Cleaning Website

Using Landing Pages to Increase Conversions

Using Landing Pages to Increase Conversions

Using Landing Pages to Increase Conversions

Landing pages are essential for small businesses in South Texas aiming to boost conversions. They are focused, standalone pages designed to turn visitors into leads by providing targeted messaging and a streamlined user experience. Key elements include compelling headlines, engaging visuals, persuasive calls-to-action, trust signals, and simplified forms. Effective landing pages can lead to significant growth, as demonstrated by local businesses in McAllen. For tailored landing page solutions, consider partnering with experts to enhance your online presence and drive results. Embrace the power of landing pages to unlock new opportunities for growth!

Keyword: Landing pages

Optometry Websites Designed to Convert New Patients

Optometry Websites Designed to Convert New Patients

The article highlights the importance of creating effective optometry websites that attract and convert new patients. It emphasizes the need for a clean design, mobile optimization, proper SEO strategies, easy booking systems, engaging content, and showcasing patient testimonials. A well-designed website not only enhances patient intake but also expands the reach beyond local markets. Ericks Webs Design specializes in crafting websites tailored for optometrists to help them succeed online.

Keyword: “optometry websites.”

How to Promote Your Website After Launch

How to Promote Your Website After Launch

After launching your website, promoting it effectively is essential for attracting customers and growing your business in South Texas. Begin by leveraging local SEO to ensure that your site ranks well for regional searches. Utilize social media to engage with your community and share valuable content. Collaborate with other local businesses for cross-promotion, and consider investing in targeted paid advertising. Lastly, keep your audience engaged through email marketing by building a subscriber list. By implementing these strategies, you’ll enhance your website’s visibility and drive traffic. Focus on local SEO to maximize your efforts.