CSS Typographic Initiatives

Ruleset interpolation proposal

There should be a way to bind keyframe animations to the size of containers, similar to how scroll-timeline binds animations to scroll depth. This would give authors more fluid control over how their websites and components scale with fewer breakpoints.

There are two possible paths this specification might take. We already have container queries and attaching an animation to that container might be a good way to keep styles consistent. The container could also be defined using a similar syntax to @scroll-timeline.

Desired features

Resize me

Container-animation

This proposal creates a more specific property focused on container interpolation as opposed to relying on animation. This sheds the baggage of time-based logic enabling container-keyframes to contain length based units. This proposal was originally discussed in this gist.

Advantages

Disadvantages

article {
  container-type: inline-size;
  container-name: article;
}

.headline {
  /* Define the container animation parameters */
  container-interpolation-name: headline;
  container-interpolation-timing-function: ease-in-out;
}

@container-keyframes headline (inline-size) {
  10rem {
    font-size: 1.2rem;
    font-weight: 900;
    color: hsl(330, 96%, 15%);
  }
  40rem {
    transform: 3rem;
    font-weight: 600;
    color: hsl(330, 96%, 45%);
  }
}

Animation attachment to a container

This is an extension of animation to allow for binding to container queries. A new function here defines the what dimension is being queried as well as the start and end points of the interpolation.

Advantages

Disadvantages

article {
  container-type: inline-size;
  container-name: article;
}

.headline {
  /* Set the animation timeline to start at a conatainer inline-size of 20rem and end at 80rem */
  /* attahment function ( container name and dimention, start size, end size ) */
  animation-attachment: container(article inline-size, 10rem, 40rem);

  /* Define the animation parameters */
  animation-name: headline;
  animation-timing-function: ease-in-out;
  animation-duration: 1s;

  /* If fill mode is not set to `both` then the animation will apply default settings outside the boundaries set in animation-attachment */
  animation-fill-mode: both;
}

/* Standard animation keyframes */
@keyframes headline {
  from {
    font-size: 1.2rem;
    font-weight: 900;
    color: hsl(330, 96%, 15%);
  }
  to {
    transform: 3rem;
    font-weight: 600;
    color: hsl(330, 96%, 45%);
  }
}

Animation timeline

This direction is more aligned with scroll-timeline. It is designed to mirror that spec, changing the syntax to @query-timeline as opposed to @scroll-timeline to define the query interpolation behavior.

Advantages

Disadvantages

/* Set the animation timeline to start at a conatainer inline-size of 20rem and end at 80rem */
@query-timeline article {
  source: selector("article");
  orientation: "inline";
  length-offsets: 10rem 40rem;
}

.headline {
  /* Set the animation timeline, much like scroll timeline is set */
  animation-timeline: article;

  /* Define the animation parameters */
  animation-name: headline;
  animation-timing-function: ease-in-out;
  animation-duration: 1s;

  /* If fill mode is not set to `both` then the animation will apply default settings outside the boundaries set in animation-attachment */
  animation-fill-mode: both;
}

/* Standard animation keyframes */
@keyframes headline {
  from {
    font-size: 1.2rem;
    font-weight: 900;
    color: hsl(330, 96%, 15%);
  }
  to {
    transform: 3rem;
    font-weight: 600;
    color: hsl(330, 96%, 45%);
  }
}