Angles, Times, Resolutions, Ratios, Positions and Images
The remaining CSS value types: angle units and their direction, times for transitions and animations, frequencies, resolutions in media queries, ratios for aspect-ratio, the position syntax with edge offsets, and choosing images with image-set().
kvi5hnuCode Sprout team member8 min readOn this page
Lengths and percentages (articles 23 and 24) aren't the only units in CSS. Rotations need angles, transitions need times, high-density screens need resolutions, and backgrounds need positions. Each type has its own rules, especially about when a unit can be left out.
Angles
| Unit | One full circle |
|---|---|
deg | 360deg |
grad | 400grad |
rad | 2π, about 6.283rad |
turn | 1turn |
.badge { rotate: -8deg; }
.spinner { animation: spin 1s linear infinite; }
@keyframes spin { to { rotate: 1turn; } }
.stripes { background: repeating-linear-gradient(45deg, #f4c95d 0 10px, #8a3b12 10px 20px); }

- Direction: in rotations and gradients, CSS angles start at the top and go clockwise.
0degpoints up,90degto the right. That's different from the math convention, which starts at the right and goes counterclockwise. turnis the clearest unit for whole rotations:3turnspins three times. The pluralturnsis invalid.- Angles can exceed one circle and be negative. That matters in animation: going from
0degto720degspins twice, while0degto0degdoesn't move. - Hues in color functions (
hsl(),oklch()) are angles, but there a plain number also works:hsl(120 50% 50%)means120deg. - Trigonometric functions work with angles:
sin(30deg),atan2(1, 1)returns45deg(article 26).

The gradients and the rotations agree: 0.25turn and 90deg are the same angle, and both point to the right.
The unit is required
Angles need a unit, even when zero: rotate: 0 is invalid, write rotate: 0deg or rotate: none. For backward compatibility, a few older places still accept a unitless 0: transform: rotate(0), skew(0, 10deg), and gradient angles such as linear-gradient(0, ...). Don't rely on those exceptions; always write the unit.
Times
<time> values use s (seconds) or ms (milliseconds): 0.3s and 300ms are the same.
.button { transition: background-color 150ms ease-out; }
.toast { animation: slide-in 0.4s 1s both; } /* 0.4s duration, 1s delay */
- The unit is always required:
transition-duration: 0is invalid; write0s. - Durations can't be negative, but delays can:
animation-delay: -1sstarts the animation as if it had already been running for one second, which is handy for staggering looped animations. - Times work in
calc():calc(var(--step) * 80ms).
Frequencies
<frequency> values use Hz or kHz. They were meant for spoken CSS, such as the pitch of a speech synthesizer, but no property in current browsers uses them. You'll only see them in specifications.
Resolutions
<resolution> values describe pixel density:
| Unit | Meaning |
|---|---|
dppx or x | dots per CSS pixel: 2x is a typical high-density screen |
dpi | dots per inch: 96dpi = 1x |
dpcm | dots per centimeter |
They're used in two places: media queries, and image-set():
@media (resolution >= 2x) {
.logo { background-image: url("logo@2x.png"); }
}
Because a CSS pixel isn't a device pixel (article 24), a phone with three device pixels per CSS pixel matches resolution: 3x. The x unit has been in all browsers since 2022, and dppx longer.
Ratios
A <ratio> is two non-negative numbers separated by a slash, width first: 16 / 9, 4/3. A single number means that number over 1: 1.5 is 1.5 / 1, and 1 is a square.
.video { aspect-ratio: 16 / 9; width: 100%; }
.avatar { aspect-ratio: 1; }
@media (aspect-ratio > 16 / 9) { /* very wide viewports */ }
A colon, as in 16:9, is invalid. Article 38 covers aspect-ratio.
Positions
A <position> places something in a box: a background image, an image's content with object-position, the center of a radial gradient, a transform origin. It's one of the most flexible syntaxes in CSS:
| Form | Example | Meaning |
|---|---|---|
| one value | left, 25%, center | the other axis is center |
| two values | right top, 25% 75%, 10px 2rem | horizontal then vertical, if lengths or percentages |
| keywords in any order | top right | keywords say which axis they're for |
| four values | right 80px bottom 60px | offsets from the named edges |
.hero { background: url("harbor.jpg") no-repeat right 2rem bottom 1rem; }
.cover img { object-fit: cover; object-position: 50% 30%; }
.glow { background: radial-gradient(circle at top left, #f4c95d, transparent 60%); }
Some rules to remember:
- With two lengths or percentages, the first is always horizontal:
10px 30pxis 10px from the left, 30px from the top. With keywords, order doesn't matter:top leftandleft topare the same, but30px leftis invalid. - Percentages align points, not edges:
25% 75%puts the point 25% across and 75% down the image at the point 25% across and 75% down the box. So0%aligns the left edges,100%the right edges, and50%centers. Article 48 shows how this works for backgrounds. - Four values measure from any edge:
right 80px bottom 60pxis 80px from the right edge and 60px from the bottom, which is hard to write any other way withoutcalc(). - Three-value forms such as
right 20px topare allowed only inbackground-position, as a legacy. Other properties that take a<position>, such asobject-position, reject them.

Compare 25% 75% with 10px 30px: a percentage moves the image's own matching point, so it never overflows, while lengths move its top left corner.
Images
An <image> can be a url(), a gradient, or one of a few functions (article 23 introduces them). The most useful of those is image-set(), which lets the browser choose a file, much like srcset in HTML:
.hero {
background-image: url("harbor.jpg"); /* fallback for old browsers */
background-image: image-set(
url("harbor.avif") type("image/avif"),
url("harbor-2x.jpg") 2x,
url("harbor.jpg") 1x
);
}
- Resolution options (
1x,2x,192dpi) let the browser pick a file for the screen's density. type()lists formats in order of preference. The browser skips types it can't decode, which lets you serve AVIF or WebP with a JPEG fallback.- Unprefixed
image-set()withtype()is Baseline since September 2023. Older Chrome and Safari only had-webkit-image-set().
For images in the HTML, <picture> and srcset are still better: the browser can choose before CSS loads, and images in HTML can have alternative text. Use image-set() for decorative backgrounds. Article 53 compares the options.
A few more types
You'll meet other value types in later articles:
| Type | Example | Article |
|---|---|---|
<color> | oklch(0.6 0.15 30) | 31 |
<flex> | 1fr | 66 |
<easing-function> | ease-out, cubic-bezier(.2,.8,.2,1) | 107 |
<transform-function> | translateX(2rem) | 103 |
<basic-shape> | circle(40%), polygon(...) | 100 |
<dashed-ident> | --card in anchor names | 59 |
What's current
xas a resolution unit and unprefixedimage-set()withtype()are Baseline.cross-fade()is still prefixed in Chromium and missing in Firefox.aspect-ratioaccepts single numbers as well asa / bratios.- Plain numbers as hues in color functions are Baseline with the modern color syntax (article 31).
Common questions
Why is rotate: 0 ignored?
Angles need a unit, even for zero. Write 0deg, or none. Only a few legacy contexts, like transform: rotate(0), accept a unitless zero.
Does 90deg point right or up?
Right. CSS angles start at the top (0deg) and go clockwise, so 90deg is to the right and 180deg points down. linear-gradient(90deg, ...) runs from left to right.
What does a negative animation delay do? It starts the animation partway through, as if it had already been running for that long. Giving each item in a list a different negative delay staggers a looping animation without waiting.
Why does background-position: 100% 100% put the image in the corner instead of off the edge?
Percentages align the same point in the image and in the box. 100% 100% aligns the image's bottom-right corner with the box's bottom-right corner.
Should I use image-set() instead of srcset?
For content images in HTML, use srcset and <picture>. image-set() is for CSS backgrounds and other images that only exist in CSS.
Summary
- Angles use
deg,grad,radorturn, start at the top and go clockwise, and need a unit even for zero. - Times use
sormsand always need a unit. Durations must be positive; negative delays start animations partway through. - Frequencies (
Hz,kHz) exist but no current property uses them. - Resolutions (
x,dppx,dpi,dpcm) appear in media queries andimage-set(). - Ratios are
width / height, or a single number. Colons are invalid. - Positions take keywords, lengths and percentages, with four-value edge offsets. Percentages align matching points.
image-set()chooses images by resolution or format, for backgrounds.
Practice questions
Which of these are invalid: rotate: 0, rotate: 0.5turn, transition-duration: 0, animation-delay: -200ms, aspect-ratio: 16:9, aspect-ratio: 1.5?
Answer
rotate: 0 (angles need a unit), transition-duration: 0 (times need a unit) and aspect-ratio: 16:9 (ratios use a slash). The others are valid.
Place a background image 1.5rem from the right edge and 1rem from the bottom of its box.
Answer
background-position: right 1.5rem bottom 1rem;
Write a background that uses an AVIF file where supported, a 2x JPEG on high-density screens otherwise, and a 1x JPEG elsewhere, with a fallback for browsers without image-set().
Answer
.banner {
background-image: url("banner.jpg");
background-image: image-set(
url("banner.avif") type("image/avif"),
url("banner-2x.jpg") 2x,
url("banner.jpg") 1x
);
}
Five dots run the same 1s looping pulse animation. How do you stagger them so they're out of step from the first frame?
Answer
Give each a different negative delay, for example with a custom property: .dot { animation: pulse 1s infinite; animation-delay: calc(var(--i) * -200ms); } and --i: 0 to 4 on the dots. Negative delays start each animation partway through, so they're already out of step.
Previous: Registered Custom Properties With @property: Types, Inheritance and Animation
Next: Dynamic Values: attr(), if(), Custom Functions and sibling-index()

More in CSS Course
Quiz: CSS Delicate Details
Twenty-five questions on the edge cases that surprise experienced developers: invalid custom properties, shorthands that reset values, layer order with !important, containing blocks, margin collapsing, specificity of :is() and :where(), intrinsic minimum sizes, and more, each checked in Chrome.
Quiz: CSS Interview Questions
Thirty front-end interview questions: cascade, specificity and layers, box model and margin collapsing, stacking contexts, positioning, flexbox and grid, responsive design, custom properties, performance, accessibility, modern selectors and architecture.
Quiz: CSS Course Final Exam
Thirty questions across the whole CSS course: syntax and error handling, selectors, the cascade and layers, values and units, color, the box model, backgrounds, positioning, flexbox, grid, responsive design, typography, generated content, effects, transforms, motion and architecture.
Quiz: CSS Architecture, Tooling and Debugging (CSS Part 17)
Twenty questions on modular CSS and BEM, layering a stylesheet, design tokens and theming, pattern libraries and safe refactoring, preprocessors and build tools, the at-rules reference, and debugging common CSS problems.
Discussion
Sign in to ask a question or share what you learned.