ray() CSS Function
The ray() function defines a straight line from a starting point at an angle, used by offset-path to move an element along it.
Description
The ray() CSS function defines a straight line segment, or "ray", that starts at a point and travels outward at a given angle. It is used with the offset-path property to move an element along that line, with offset-distance controlling how far along it the element sits. This makes it easy to create radial menus, burst effects and elements that fly out from a centre point.
The angle is measured clockwise from straight up, so 0deg points up and 90deg points right. The size keyword sets the length of the ray: closest-side, closest-corner, farthest-side, farthest-corner (the default) or sides, measured from the start point to the edges of the containing block. Adding contain shortens the ray so the element stays completely inside the containing block at 100%. The optional at <position> sets the start point; if it is omitted, the element's offset-position is used.
/* Fly an element out from the centre at 45 degrees */
.spark {
offset-path: ray(45deg closest-side contain at 50% 50%);
animation: fly 1s ease-out forwards;
}
@keyframes fly {
from { offset-distance: 0%; }
to { offset-distance: 100%; }
}
By default, an element following a ray is rotated to point along it, controlled by offset-rotate. Set offset-rotate: 0deg to keep it upright.
Interactive Demo
Syntax
ray() = ray( <angle> && <ray-size>? && contain? && [ at <position> ]? )
<ray-size> = closest-side | closest-corner | farthest-side | farthest-corner | sides
Values
- <angle>The direction of the ray, measured clockwise from straight up (0deg).
- <ray-size>Optional. The length of the ray: closest-side, closest-corner, farthest-side, farthest-corner (default) or sides.
- containOptional. Shortens the ray so the element stays fully inside its containing block at offset-distance: 100%.
- at <position>Optional. The start point of the ray. Defaults to the element's offset-position.
Example
Browser Support
The following information will show you the current browser support for the CSS ray() function. Hover over a browser icon to see the version that first introduced support for this CSS function.
Desktop





Tablets & Mobile





