Categories
Content Management

Article – CSS Animations

What is CSS animation?

CSS animations are a way to add movement and interactivity to web pages using only CSS code, without the need for JavaScript or other programming languages. With CSS animations, we can create dynamic effects such as moving text and images, colour and font changes, and plenty of other visual touches.

CSS is a powerful tool that is often capable of more than we can imagine. Andy Clarke’s take on the AMC show Mad Men‘s opening credits is a testament to what CSS can accomplish:

Why use CSS animation?

There are several reasons why you might want to use CSS animations in your web design:

  1. Eye-catching visuals: CSS animations can make your website more visually appealing and engaging for users. Animations can help to draw attention to important elements on the page, and create a sense of interactivity that can make the user experience more enjoyable.
  2. Improved user experience: Animations can also be used to improve the user experience by providing visual feedback when a user interacts with a particular element on the page. For example, when a user hovers over a button, the button might change colour or move slightly, giving the user a sense of feedback that their action has been registered.
  3. Cross-browser compatibility: CSS animations are supported by all modern browsers. Older browsers can be accounted for with vendor prefixes, which we will cover later on.
  4. Performance: Because CSS animations are native to the browser, they tend to be faster and more efficient than animations created using JavaScript. This can help to improve the performance of your website and ensure that it loads quickly for users. Also, why use the most fragile layer to create animations when we can make them using CSS, the more robust layer?

How to use CSS animation

Before we jump into some animations, let’s take a look at what CSS technologies are available to us and how they work.

The transform property is an extremely useful tool that allows us to move, resize, rotate, and skew HTML elements on the page. It should be noted that while transforms change how the element is displayed, it is does not create ‘movement’ or animation when used by itself. The trick is to combine the transform property with a transition or keyframe animation.

The following functions can be performed with transform:

translate: Relocates the element on the page. This can be done on the horizontal axis with transform: translateX(), the vertical axis with transform: translateY(), or both the X and Y axis with translate().

scale: Makes an element appear larger or smaller. You can provide a ratio with scale, such as transform: scale(1.5). This would make the element 150% larger than its original size.

skew: Changes the angle of the element’s axis by a specified number of degrees, stretching it out accordingly. In other words, it makes the element ‘slanty’. You can do this on the horizontal axis with scaleX(), vertically with scaleY(), or both with scale().

rotate: Tilts the element’s angle clockwise with a positive degree value, or anti-clockwise with a negative degree value. For example, to rotate an element by 45 degrees, you would write transform: rotate(45deg).

Here’s a quick look at how we can apply multiple transforms to manipulate an image of a cloud:

If we wanted to move the cloud to the right, make it smaller, and rotate it slightly, we could write:

The result is a cloud that has been moved 500px to the right, scaled to half its size, and rotated to a 30 degree clockwise angle.

Transitions in CSS are an integral part of animation and are often used in conjunction with the transform property to create smooth and fluid transitions between different states of an element.

Transitions allow you to specify how an element’s property should change over time, and is activated when a user interacts with the element, such as hovering over it or clicking on it. Transitions enable us to control the speed and timing of the change, creating a smooth sense of motion.

The syntax for transitions consists of:

transition: [transition-property] [transition-duration] [transition-timing-function] [transition-delay];

To break it down:

  • [transition-property] – selects the element property you wish to change
  • [transition-duration] – the duration of the change in seconds
  • [transition-timing-function] – how the transition is executed over time
  • [transition-delay] – an optional delay can be placed on the transition

Here’s an example of a transition applied to an element’s background colour that changes over a 0.3 second period:

transition-property: background-color;

transition-duration: 0.3s;

transition-timing-function: ease-in-out;

That’s all a bit wordy, but we can use shorthand to make our lives much easier:

transition: background-color 0.3s ease-in-out;

Many CSS properties are animatable with transitions. Here’s a handy list of some of them as seen in Jennifer Niederst Robbins’ book Learning Web Design:

However, if we just want a quick, one-size-fits-all for all of our state changes on an element without targeting things like the background colour or width individually, we can use the rather nifty all value for transition-property. This targets all of the changes you make to the element.

transition: all 0.3s ease-in-out;

A closer look at the transition-timing-function

The transition-timing-function dictates how the transition speeds up or slows down while it is being carried out. For example, the transition might begin slowly, then pick up the pace through to the end (otherwise known as ease-in). You might prefer it to ease slowly into the transition, speed up in the middle, then slow down towards the end (ease-in-out).

The transition pace can be imagined as following a curve, where it flattens as the pace slows, and inclines as it speeds up. This is known as the cubic bezier.

An example of a simple transition

In this little animation of a car driving along a road, perhaps we want to move that cloud slowly to the left when we hover over it, just to give an impression of some extra movement. We would need to perform a transform on it that translates it on its x axis.

Don’t worry about all those strange -webkit prefixes just yet. We’ll get to them.

Here we use the transition property to specify that the cloud should move horizontally by 1400px over a duration of 7 seconds. Using ease-in-out, the cloud starts off slowly when we hover over it, builds momentum as it moves to the left, then slows down towards the end of the transition. Note that the transition is applied to the cloud image itself, while the transform property belongs with the triggering event (in this case, .clouds:hover).

View this animation here.

Browser support for transitions

Luckily, CSS transitions are supported by most modern web browsers. That said, the level of support may vary depending on the version of the browser, and some older browsers may not support certain CSS animation features. As a general rule, we should not expect to encounter any issues with browser versions released after 2013. To check which browsers support transitions, you can refer to online resources such as CanIUse.com, which gives comprehensive information on the support for various CSS features across different web browsers, including version numbers and any known issues or limitations.

You might have spotted some vendor prefixes in our hovering cloud example code above. Just on the off-chance that someone views your site in an older browser, you can use vendor prefixes in your transitions to ensure that they will run. We can also let someone else do the hard work for us by heading to autoprefixer.github.io, which parses our CSS and generates the vendor prefixes we need to include in our code.

Autoprefixer can do all the heavy lifting for us.

Here’s an example of a transition that uses vendor prefixes to support older browsers. Each link icon has a transform: scale() on hover applied to it with a transition:

These prefixes cover older versions of Safari, Firefox, and Opera respectively. Note that the ‘plain’ transition goes last in the cascade.

Keyframes can be considered animation ‘proper’; they do not need to rely on a user interaction to execute, and can run a certain number of times or even infinitely if desired. Keyframes can dictate exactly how an element’s state changes, and you can explicitly express not just the beginning and end points of the animation, but any part of it in between. Keyframes can be used in conjunction with transforms to produce a variety of effects.

Once the keyframes have been defined, the animation property that references the keyframes can be applied directly to the element you would like to animate. It is easiest to think of the keyframes as an animation ‘script’ that can then be referenced where it is needed.

The syntax for keyframe animations is made up of two parts:

Part 1: Defining the keyframes

@keyframes name-of-animation {

0% { opacity: 0; }

20% { opacity: 1; }

80% { opacity: 0; }

100% { opacity: 1; }

}

After naming our animation, we can define exactly what happens in the animation using percentages, with 0% denoting the start of the animation and 100% signifying the end. In this case, the element’s opacity will change in intervals.

We are not limited to percentages, however, and can simply use the from and to keywords to define the start and end of the animation, as we see in this animation named whoosh that uses transform: translate() to move an element to the left.

@keyframes whoosh {

from {transform: translateX(0) }

to {transform: translateX(-400) } }

Part 2: Calling the animation

.animate-this-element {

animation: name-of-animation 5s infinite;

}

The animation property is then used on the target element to call the defined keyframes and change the state of the element as desired. Above, shorthand has been used to reference the animation name, the animation’s duration, and the number of times the animation will run. In full, the animation properties include:

For efficiency, it is a good idea to use shorthand animation properties. They should also look rather familiar, as they are very similar to transition properties.

  • animation-name (required) – the name of the animation as specified in the keyframes
  • animation-duration(required) – usually given in seconds
  • animation-timing-function – options include ease, ease-in, linear, and all the timing-function values we have already encountered with transitions
  • animation-iteration-count – how many times the animation should repeat. This can be a number or set to infinite
  • animation-direction – this defines whether the animation plays forward (normal), backwards (reverse), or back and forth (alternate). You can also start the animation from the end with alternate-reverse.

A simple example of a keyframe animation

Let’s drive our car from earlier on.

We begin by defining our keyframes. The car is a PNG image that will move from the left to the right of the page by 1500px. We can use from and to to do this:

The animation is then called on the car element.

The animation will last for 5 seconds and run infinitely on a loop.

Combining multiple transform properties with keyframe animations

We can combine transforms to create more complex and dynamic effects. In the example below, a sense of movement and perspective is gained in our desert highway scene by combining scale and translate on elements. As they approach the ‘camera’ and get closer, their sizes increase.

The white road marking is moved to the bottom of the page with translateY, and it is scaled up over time. This gives the impression of driving from a first-person perspective.

When we call the animation on our .lines element, we set it to run at a steady pace for 2 seconds with linear on an infinite loop.

Combining multiple transforms can produce a variety of effects.

View this animation page here.

Working with SVG

SVG elements (Scalable Vector Graphics) are an increasingly popular choice for adding movement to web pages, and can be used with CSS to make simple animations. They can also be animated with the XML language SMIL as well as JavaScript to create more complex animations. However, it would be wise to use SVG sparingly when animating due to poor browser support. Indeed, it is a good idea to consider fallback techniques.

CSS fallback for SVG

In our desert scene animation, the sun is a SVG sprite that changes colour when clicked and hovered upon, using a flipbook-like mechanic where three sun images are combined. However, if the user’s web browser does not support SVG, the animation will not work.

The sprite changes position as the user interacts with it.

As a fallback, we have set a PNG of the sprite image just before the SVG version in the cascade. This way, the sun will still appear and work as expected, even if an older browser is being used.

More on CSS Animation Fallbacks

There are several types of CSS fallbacks that can be used for animations to ensure that the animation is still presentable and works as expected, even if the user’s browser doesn’t support the animation effect.

Here are some common types of CSS fallbacks used for animations:

  • Static fallbacks: These are simple styles that are applied to the element if the animation is not supported. For example, if you have a CSS animation that rotates an element, you might apply a transform: none property to the element as a static fallback so that it still looks good and is positioned correctly even if the rotation effect is not supported.
  • Feature detection: One way to provide a fallback is to use feature detection to determine whether a particular CSS animation effect is supported by the user’s browser. If it is not, you can use a different animation effect or a static fallback instead. This approach requires some additional coding, but can help ensure that your website works as expected for all users.
  • Progressive enhancement: Another approach is to use progressive enhancement, where you start with a simple, static design that works for all users, and then add more complex animation effects using CSS and JavaScript for users with newer browsers that support these features.

By using these types of fallbacks, you can ensure that your animations still look presentable and work as expected, even if some users are not able to see the full animation effect. This can help improve the accessibility and usability of your website for a wider range of users.

Things to bear in mind when animating

It’s important to remember that by providing fallbacks, you can ensure that your website is still usable and accessible for all users, regardless of their browser or device.

Next, we may choose to (and probably should) make use of the prefers-reduced-motion media query in our CSS to detect whether users have opted for reduced animation in their accessibility preferences. Many users suffer from motion disorders and other sensory conditions, and we need to account for them in our design.

We should also consider how animation should be used, and how much is too much. After all, while a bit of polish and flair goes a long way, we do not want our website to become a 2002 Geocities page full of flashy graphics and whirling GIFs.

When used with consideration, animations can greatly enhance the user experience and bring some added delight to our web pages.

References

  1. Seminar slides – https://zaraknox.co.uk/coursework/content-management/slides.pdf
  2. Chapter 18 of Learning Web Design by Jennifer Niederst Robbins: Transitions, Transforms, and Animation, 5th Edition 2018
  3. CSS animations – https://developer.mozilla.org/en-US/docs/Web/CSS/animation
  4. CSS animations – https://css-tricks.com/almanac/properties/a/animation/
  5. Transform, transition, keyframes and animation – https://www.youtube.com/watch?v=jgw82b5Y2MU&list=PL4cUxeGkcC9iGYgmEd2dm3zAKzyCGDtM5
  6. SVG Fallbacks – https://css-tricks.com/a-complete-guide-to-svg-fallbacks/

Categories
Crit Major Project

Crit 3: Delight

Planning and Moodboard here.

Branding and Visual Design: how will your brand express its mission?

In my research for my proposed website, I determined that the users of my site are primarily:

  • women aged 35-44
  • looking for a creative outlet
  • keen to craft as a means of alleviating stress

Furthermore, these users may:

  • have little free time
  • be unsure of how to get started
  • have varying experience levels and budgets

These concepts will factor heavily into the visual design and content of my website. As explored in my Commodity Crit, the site content will need to include:

  • concise video tutorials with audio
  • clear written instructions in tutorials
  • a section on safety
  • information on where materials can be sourced, as well as their cost
  • An about section that gives some insight into the project’s concept and mission

Tone of language

Authenticity of tone

When writing content, it is important to strive to arrive at the ‘truth’. To clarify, there is a difference between writing what the author thinks sounds good, or what they think the reader expects to hear, as opposed to writing what actually needs to be said. This can arise if the author is overly influenced by cognate site content, and instead of searching for their own voice that fits their site mission, chooses to imitate what has already been said, regardless of whether or not it is relevant. I will therefore not look for inspiration from cognate sites when considering the tone of my website.

During my research for the project, I interacted with the Resin community on Reddit to find out what drew them to the craft. The replies were open, warm, and helpful. Some gave very detailed replies and were not afraid of opening up about their personal circumstances. The tone was therefore friendly and informal, but often struck more sombre notes as they disclosed more distressing reasons for needing to find a creative outlet. Several users also mentioned that they found it difficult to know where to start.

Setting the tone of language in my website is therefore potentially challenging in that it needs to bear in mind that users need to find information quickly, but also feel welcomed and ‘safe’ in introducing them to a craft that could possibly seem overwhelming for beginners. This means that the tone needs to be simultaneously concise and minimal while being warm and friendly in tone.

The focus on the therapeutic side of learning a craft also means that I would like to avoid using overly excitable, bubbly language, such as the use (or overuse) of exclamation marks and emphasis including uppercase ‘shouting’, which can serve as a distraction and trivialise the reasons that led to the user wanting to learn to make resin. Instead, the site should use soothing, friendly language. The underlying tone can be summarised as:

“Let’s have a nice sit down and make some lovely things together.”

Visual Design

To begin the process of establishing a brand identity, I started by brainstorming words that could be associated with the site’s content and mission.

Calming, therapeutic words:

tranquility

lagoon

oasis

azure

serene

cure

therapy

heal

raindrop

Artistic, crafty words:

create

curate

inspire

craft

canvas

pour

Name

cure8:

the concept of therapy and healing

the resin curing process

curate – appealing to those looking for artistic projects

8 – 5 mins of mixing, 3 mins of pouring, arranging, no video tut longer than 8 mins

Initially I had come up with resin8, but this was unfortunately taken by a resin e-commerce site. However, cure8 combines the idea of therapy and art, as well as the short time one can spend on the craft.

Colour

From these words (particularly the ‘therapeutic’ words), it is possible to draw connotations. In regard to colour, the words bring up ideas of cool, relaxing blues and turquoises reminiscent of the sea, or perhaps a swimming pool. These would contrast well against a cool, off-white background for a simple, minimalistic feel.

Next, I explored cognate sites to see if there were any commonalities in their colour schemes. I noted that resin8.co.uk uses a teal colour for its logo, while houseofresin.co.uk uses a similar shade for its headings. Indeed, there seems to be an existing connotation between resin art and the colour blue, or more specifically turquoises and teals. Furthermore, the dominant recurring colours in search results for ‘resin’ are shades of blue and turquoise.

A closer inspection of the resin8.co.uk site shows that there is a lot of red on banners announcing item sales, as well as confetti imagery and uppercase lettering. The result is eye-catching and loud, but highlights the site’s primary mission of being an e-commerce site. Red, with its connotations of aggression and anger, would not be suited to a site that promotes resincraft as a therapeutic exercise.

However, to prevent the turquoise and whites from looking too clinical and related to healthcare (such as the now defunct Theranos website), the turquoise should be offset by a contrasting, warm colour. Complementary colours for turquoise include deep reds and burnt oranges, but as established, these can appear alarming and subtract from the calm tone. It would be therefore worth considering a lighter shade of ochre or orange, perhaps reminiscent of sunshine and positivity. This shade could be used lightly throughout the site.

Type

As my users will most likely be busy people looking for clear guidance on how to start making resin, fonts for the site should be clear, easily scannable and simple. I therefore propose to use a sans-serif font for both headers and body text. There will certainly be no more than two font families on the site. I would like such fonts to be more rounded rather than angular to keep the theme of being soothing and calming, and not ‘edgy’. The Google Font Paytone One, with its thick, bold characters may suit this task, but Archivo Black might be easier for those in a hurry to skim-read due to its larger counters, making each letter more distinctive.

Information Architecture

The website structure will be simple and scaled down, primarily so that new crafters are not overwhelmed by too many options. The pages will consist of:

Home – the landing page

Getting Started – a guide on what equipment to buy, how a workstation should be set up

Tutorials (with a dropdown for each tutorial page) – video with text instructions beneath

Safety – safety precautions for working with resin and recommended gear/measures

About – describing the site’s mission

Layout

Due to user time constraints, I plan to take a minimalistic approach to the site layout. Users should not be overwhelmed by choice, and as such will not be presented with too many navigation options.

The homepage would potentially take a full page spread format, with the navigation options clearly grouped together in the centre. This helps guide the user to the exact content they need.

Other pages, such as the tutorial pages, would take on a more conventional design pattern, with a top and footer navigation. As there will be minimal nav options, I would prefer not to use a collapsible hamburger menu for smaller viewports, and let users directly see their options as soon as they arrive on the page.

Imagery and Iconography

Starting with the concept of art as therapy, I am interested in using images associated with healthcare as part of my imagery. Glass apothecary jars/Florence Flasks, as seen in chemists of yesteryear, might suit this idea. With their jewel-like appearance, these multicoloured jars of coloured water are also reminiscent of what can be created with resin itself. It would therefore be interesting to see if this could be incorporated into the logo.

A turquoise wave would also be an interesting addition, perhaps used to separate the footer. This would fit into the thematic ideas of the ocean explored during my word association exercise.

Icons that denote each page of the site in the navbar would need to be instantly recognisable to users scanning through quickly to view the site content. These will be created with SVGs.