CSS Shapes Module Level 1 (original) (raw)
Abstract
CSS Shapes describe geometric shapes for use in CSS. For Level 1, CSS Shapes can be applied to floats. A circle shape on a float will cause inline content to wrap around the circle shape instead of the float’s bounding box.CSS is a language for describing the rendering of structured documents (such as HTML and XML) on screen, on paper, in speech, etc.
Status of this document
This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.
Publication as a Last Call Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.
The (archived) public mailing list www-style@w3.org (seeinstructions) is preferred for discussion of this specification. When sending e-mail, please put the text “css-shapes” in the subject, preferably like this: “[css-shapes] _…summary of comment…_”
This document was produced by the CSS Working Group (part of the Style Activity).
This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
This is a Last Call Working Draft. The deadline for comments is 7 January 2014.
The important changes since the previous drafts are:
- The rectangle() shape has been dropped. (It may come back with different features in a future version.)
- inset-rectangle() is now called inset().
- Some changes to the syntax of the parameters of various shape functions.
- 'Shape-outside' now also accepts 'margin-box', 'border-box' and 'content-box' as keywords to define a shape or the base for a shape.
- 'shape-margin' also accepts percentages.
Table of contents
- 1Introduction
- 2Relation to the box model and float behavior
- 3Basic Shapes
- 4Shapes from Image
- 5Shapes from Box Values
- 6Declaring Shapes
- Acknowledgments
- Change Log
- Conformance
- References
- Index
- Property index
1 Introduction
This section is not normative.
Shapes define arbitrary geometries that can be used as CSS values. This specification defines properties to control the geometry of an element’s float area. The shape-outside property uses shape values to define the float area for a float.
Note: Future levels of CSS Shapes will allow use of shapes on elements other than floats. Other CSS modules can make use of shapes as well, such as CSS Masking [CSS-MASKING] and CSS Exclusions [CSS3-EXCLUSIONS].
Note: If a user agent implements both CSS Shapes and CSS Exclusions, the shape-outside property defines the exclusion area for an exclusion.
Note: A future level of CSS Shapes will define a shape-inside property, which will define a shape to wrap content within the element.
1.1 Module Interactions
This module extends the float features defined in [CSS21] chapter 9.
1.2 Values
This specification follows the CSS property definition conventions from [CSS21]. Value types not defined in these specifications are defined in CSS Values and Units Module Level 3 [CSS3VAL].
In addition to the property-specific values listed in their definitions, all properties defined in this specification also accept the inherit keyword as their property value. For readability it has not been repeated explicitly.
1.3 Animated Values
It is expected that CSS will include ways to animate transitions between styles. (The section "Animation of property types" of the CSS Transitions module [CSS3-TRANSITIONS] is expected to define how different kinds of values are interpolated during a transition.) In anticipation of that, this module includes a line "Animatable" for each property, which specifies whether and how values of the property can be animated.
1.4 Terminology
This specification uses the term wrap to refer to flowing content around the sides of a float area, defined in [CSS21] chapter 9. Content wraps around the right side of a left-floated box, and content wraps around the left side of a right-floated box. One result of this wrapping is that line boxes next to a float are shortened as necessary to avoid intersections with the float area.
The area used for wrapping content around a float element. The rules for float behavior use the sides of the float area to determine where content flows. By default, the float area is the float element’smargin box. This specification’s shape-outside property can be used to define an arbitrary, non-rectangular float area.
2 Relation to the box model and float behavior
While the boundaries used for wrapping inline flow content outside a float can be defined using shapes, the actual box model does not change. If the element has specified margins, borders or padding they will be computed and rendered according to the [CSS3BOX] module. Also, float positioning and stacking are not affected by defining a float area with a shape.
When a shape is used to define a float area, the shape is clipped to the float’s margin box. In other words, a shape can only ever reduce a float area, not increase it. A reduced float area may have no effect on some line boxes that would normally be affected by the float. An empty float area (where the shape encloses no area) has no effect on line boxes.
A float area defined by a shape may reduce the normal float area on all sides, but this does not allow content to wrap on both sides of a float. Left floats with a shape-outside still only allow content wrapping on the right side, and right floats only allow wrapping on the left.
In the following example the left and right floatingdiv
elements specify a triangular shape using the shape-outside property.
`
`
Since shapes are clipped to the float’s margin box, adding this shape to the left float above would result in the same rendering.
shape-outside: polygon(0 0, 500% 500%, 0 500%);
A shape with no extent will create a float area with no extent. Because wrapping only considers the float area, either shape below applied to a float will allow inline content to flow through all of the float’s box.
shape-outside: inset(50% 50% 50% 50%); shape-outside: inset(150% 150% 0% 0%);
A shape-outside can create open areas on both the left and right of a float area. Content still wraps only on one side of a float in this case. In the picture, the shape is rendered in blue, and the content area outside the shape in mauve.
shape-outside: polygon(50px 0px, 100px 100px, 0px 100px);
The following styling creates a shape much smaller than the float’s content area, and adds a margin-top to the float. In the picture, the shape is rendered in blue, the content area outside the shape in mauve, and the margin area of the float box in yellow. The inline content only wraps around the shape, and otherwise overlays the rest of the float margin box.
.float-left {
shape-outside: polygon(0% 50%, 50% 100%, 0 100%);
float: left;
width: 100px;
height: 100px;
margin-top: 20px;
}
The next picture shows a possible result if two of these floats were stacked next to each other. Note that the floats are positioned using their margin boxes, not the float area.
3 Basic Shapes
The type can be specified using basic shape functions. The definitions use the and types. When using this syntax to define shapes, the reference box is defined by each property that uses values. The coordinate system for the shape has its origin on the top-left corner of thereference box with the x-axis running to the right and the y-axis running downwards. All the lengths expressed in percentages are resolved from the used dimensions of the reference box.
3.1 Supported Shapes
The following shapes are supported. All values usefunctional notation and are defined here using theValue Definition Syntax.
inset() = inset( {1,4} [round <border-radius>]? )
Defines an inset rectangle.
- The first four arguments represent thetop, right, bottom andleft offsets from the reference box inward that define the positions of the edges of the inset rectangle. These arguments follow the syntax of the margin shorthand, that let you set all four insets with one, two or four values.
- The optional <‘border-radius’> argument(s) define rounded corners for the inset rectangle using the border-radius shorthand syntax.
A pair of insets in either dimension that add up to more than the used dimension (such as left and right insets of 75% apiece) define a shape enclosing no area. For this specification, this results in an empty float area.
circle() = circle( []? [at ]? )
- The shape-radius argument representsr, the radius of the circle. Negative values are invalid. A percentage value here is resolved from the used width and height of the reference box as
sqrt(_width_2+_height_2)/sqrt(2)
. - The position argument defines the center of the circle. This defaults to center if omitted.
ellipse() = ellipse( [{2}]? [at ]? )
- The shape-radius arguments representrx andry, the x-axis and y-axis radii of the ellipse, in that order. Negative values for either radius are invalid.
- The position argument defines the center of the ellipse. This defaults to center if omitted.
polygon() = polygon( [,]? [ ]# )
- - The filling rule used to determine the interior of the polygon. See fill-rule property in SVG for details. Possible values are nonzero or evenodd. Default value when omitted is nonzero.
- Each pair argument in the list represents xi and yi - the x and y axis coordinates of the i-th vertex of the polygon.
The UA must close a polygon by connecting the last vertex with the first vertex of the list.
At least three vertices are required to define a polygon with an area. This means that (for this specification) polygons with less than three vertices (or with three or more vertices arranged to enclose no area) result in an empty float area.
The arguments not defined above are defined as follows:
= | | closest-side | farthest-side
Defines a radius for a circle or ellipse. If omitted it defaults to closest-side.
- closest-side uses the length from the center of the shape to the closest side of the reference box. For circles, this is the closest side in any dimension. For ellipses, this is the closest side in the radius dimension.
- farthest-side uses the length from the center of the shape to the farthest side of the reference box. For circles, this is the farthest side in any dimension. For ellipses, this is the farthest side in the radius dimension.
3.2 Interpolation of Basic Shapes
For interpolating between one basic shape and a second, the rules below are applied. The values in the shape functions interpolate as a simple list. The list values interpolate as length, percentage, or calc where possible. If list values are not one of those types but are identical (such as finding left in the same list position in both lists) those values do interpolate.
- Both shapes must use the same reference box.
- If both shapes are the same type, that type is ellipse() or circle(), and none of the radii use the closest-side or farthest-side keywords, interpolate between each value in the shape functions.
- If both shapes are of type inset(), interpolate between each value in the shape functions.
- If both shapes are of type polygon(), both polygons have the same number of vertices, and use the same , interpolate between each value in the shape functions.
- In all other cases no interpolation is specified.
4 Shapes from Image
Another way of defining shapes is by specifying a source whose alpha channel is used to compute the shape. The shape is computed to be the path that encloses the area where the opacity of the specified image is greater than the shape-image-threshold value. If the shape-image-threshold is not specified, the initial value to be considered is 0.0.
The image is sized and positioned as if it were a replaced element with a specified width and height of the element’s used content-box size.
For animated raster image formats (such asGIF), the first frame of the animation sequence is used.
An image is floating to the left of a paragraph. The image shows the 3D version of the CSS logo over a transparent background. The logo has a shadow using an alpha-channel.
The image defines its float area through the shape-outside property.
`
blah blah blah blah...
<style>
#CSSlogo {
float: left;
shape-outside: attr(src url);
shape-image-threshold: 0.1;
}
</style>
`
The shape-outside property re-uses the url from the src attribute of the img element.
It is perfectly possible to display an image and use a different image for its float area.
In the figure below, the alpha-channel threshold is represented by the dotted line around the CSS logo.
It’s then possible to affect where the lines of the paragraph start in three ways:
- Modifying the alpha channel in the image
- Changing the value of the shape-image-threshold property
- Changing the value of the shape-margin property (see example 8)
A float shape around an image using its alpha-channel.
5 Shapes from Box Values
Shapes can be defined by reference to edges in the CSS Box Model. These edges include border-radius curvature [CSS3BG]. The definitions of the values are:
The margin-box value defines the shape enclosed by the outside margin edge. The corner radii of this shape are determined by the corresponding border-radius and margin values. If the ratio of border-radius/margin
is 1 or more, then the margin box corner radius is border-radius + margin
. If the ratio of border-radius/margin
is less than 1, then the margin box corner radius is border-radius + (margin * (1 + (ratio-1)^3))
.
The border-box value defines the shape enclosed by the outside border edge. This shape follows all of the normal border radius shaping rules for the outside of the border.
The padding-box value defines the shape enclosed by the outside padding edge. This shape follows all of the normal border radius shaping rules for the inside of the border.
The content-box value defines the shape enclosed by the outside content edge. Each corner radius of this box is the larger of 0 or border-radius - border-width - padding
.
Given the 100px square below with 10px padding, border and margins, the box values define these shapes:
- margin-box: the shape containing all of the yellow pixels
- border-box: the shape containing all of the black pixels
- padding-box: the shape containing all of the mauve pixels
- content-box: the shape containing all of the blue pixels
Simple CSS Box Model Edges
And the same definitions apply to a more complex example with the same 100px square, but with these border, padding and margin properties:
border-radius: 20px 20px 20px 40px; border-width: 30px 10px 20px 10px; padding: 10px 20px 10px 10px; margin: 20px 10px 10px 10px;
Complex CSS Box Model Edges
6 Declaring Shapes
Shapes are declared with the shape-outside property, with possible modifications from the shape-margin property. The shape defined by the shape-outside and shape-margin properties changes the geometry of a float element’sfloat area.
6.1 The shape-outside Property
Name: | shape-outside | ||
---|---|---|---|
Value: | auto | [ | ] | |
Initial: | auto | ||
Applies to: | floats | ||
Inherited: | no | ||
Media: | visual | ||
Computed value: | computed lengths for , the with its URI made absolute, otherwise as specified | ||
Animatable: | as specified for , otherwise no |
The values of this property have the following meanings:
The float area uses the margin box as normal.
If one of these values is specified by itself the shape is computed based on one of margin-box, border-box, padding-box or content-box which use their respective boxes including curvature from border-radius, similar to background-clip [CSS3BG].
The shape is computed based on the values of one of inset(), circle(), ellipse() or polygon(). If a is also supplied, this defines the reference box for the function. If is not supplied, then the reference box defaults to margin-box.
The shape is extracted and computed based on the alpha channel of the specified as defined by shape-image-threshold.
User agents must use thepotentially CORS-enabled fetch method defined by the [HTML5] specification for all URLs in a shape-outside value. When fetching, user agents must use "Anonymous" mode, set the referrer source to the stylesheet’s URL and set the origin to the URL of the containing document. If this results in network errors such that there is no valid fallback image, the effect is as if the value auto had been specified.
6.2 The shape-image-threshold Property
The shape-image-threshold defines the alpha channel threshold used to extract the shape using an image. A value of 0.5 means that the shape will enclose all the pixels that are more than 50% opaque.
Name: | shape-image-threshold |
---|---|
Value: | |
Initial: | 0.0 |
Applies to: | floats |
Inherited: | no |
Media: | visual |
Computed value: | The same as the specified value after clipping the to the range [0.0,1.0] |
Animatable: | as number |
The values of this property have the following meanings:
Sets the threshold used for extracting a shape from an image. The shape is defined by the pixels whose alpha value is greater than the threshold. A threshold value outside the range 0.0 (fully transparent) to 1.0 (fully opaque) will be clamped to this range.
Note: A future level of CSS Shapes may define a switch to use the luminance data from an image instead of the alpha data. When this happens, shape-image-threshold will be extended to apply its threshold to either alpha or luminance, depending on the switch state.
6.3 The shape-margin property
The shape-margin property adds a margin to a shape-outside. This defines a new shape that is the smallest contour (in the shrink-wrap sense) that includes all the points that are the shape-margin distance outward in the perpendicular direction from a point on the underlying shape. Note that at points where a perpendicular is not defined (e.g. sharp points) take all points on the circle centered at the point and with a radius of shape-margin. This property takes only non-negative values.
Name: | shape-margin |
---|---|
Value: | | |
Initial: | 0 |
Applies to: | floats |
Inherited: | no |
Media: | visual |
Computed value: | the absolute length |
Animatable: | as length, percentage, or calc. |
Sets the margin of the shape to the .
Sets the margin of the shape to a percentage of the width of the element’s containing block.
A shape-margin creating an offset from a polygonal shape-outside. The lighter blue area shows the shape in a 100x100px float, and the darker blue area shows the 10px offset.
.float { shape-outside: polygon(10px 10px, 90px 50px, 40px 50px, 90px 90px, 10px 90px); shape-margin: 10px; }
If shape-margin is added to the CSS logo from example 6, the line boxes wrapping around the shape are shortened further.
#CSSlogo { shape-margin: 35px; }
A float shape around an image using its alpha-channel with a 35-pixel shape-margin
Acknowledgments
This specification is made possible by input from Andrei Bucur, Alexandru Chiculita, Elika Etemad, Arron Eicholz, Daniel Glazman, Arno Gourdol, Zoltan Horvath, Chris Jones, Bem Jones-Bey, Marcus Mielke, Alex Mogilevsky, Hans Muller, Mihnea Ovidenie, Virgil Palanciuc, Dirk Schulze, Peter Sorotokin, Bear Travis, Eugene Veselov, Stephen Zilles and the CSS Working Group members.
Change Log
Since June 20th 2013
- Added shape from box value section
- Updated basic-shape interpolation
- Allow negative insets, disallow negative radii
- Changed relevant to reference
- Remove box-sizing dependency, add relevant box keywords
- Changed circle() and ellipse() to use radial gradient syntax
- Postponed rectangle() to level 2
- Clarified shape-from-image sizing and positioning
- Change inset-rectangle() to inset()
- Future-proof shape-image-threshold to possibly apply to luminance
- Added CORS fetching to shape-outside URLs
- Changed shape-outside value from to
- Remove 'percentages based on auto-sizing resolve to 0'
- Change initial value of shape-image-threshold to 0.0
- Change float positioning to be unaffected by shape-outside
- Shapes on floats clipped to float’s margin box
Since May 3rd 2012
- Postpone shapes from SVG elements to a future Shapes level
- Postpone shape-inside to a future Shapes level
- split exclusions from shapes into separate modules
- added inset-rectangle() to basic shapes
- Changed shape-inside overflow diagrams to show exclusion behavior
- Changed shape-inside to contribute to the wrapping context
- Defined exclusion edges relative to wrapping content’s writing mode
- Made use of start, end, before and after consistent
- Added interpolation for basic shapes
- Changed basic shapes to depend on box specified with box-sizing
- Added overflow behavior for shape-inside.
- Added wrap-flow:minimum.
- Clarified processing model.
- Changed wrap-margin and wrap-padding to shape-margin and shape-padding.
- Removed wrap shorthand.
Since December 13th 2011
- Clarified processing model.
- Clarified interaction with floats.
- Clarified that an exclusion element establishes a new block formatting context.
Conformance
Document conventions
Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification.
All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]
Examples in this specification are introduced with the words "for example" or are set apart from the normative text with class="example"
, like this:
This is an example of an informative example.
Informative notes begin with the word "Note" and are set apart from the normative text with class="note"
, like this:
Note, this is an informative note.
Conformance classes
Conformance to this specification is defined for three conformance classes:
style sheet
renderer
A UA that interprets the semantics of a style sheet and renders documents that use them.
authoring tool
A UA that writes a style sheet.
A style sheet is conformant to this specification if all of its statements that use syntax defined in this module are valid according to the generic CSS grammar and the individual grammars of each feature defined in this module.
A renderer is conformant to this specification if, in addition to interpreting the style sheet as defined by the appropriate specifications, it supports all the features defined by this specification by parsing them correctly and rendering the document accordingly. However, the inability of a UA to correctly render a document due to limitations of the device does not make the UA non-conformant. (For example, a UA is not required to render color on a monochrome monitor.)
An authoring tool is conformant to this specification if it writes style sheets that are syntactically correct according to the generic CSS grammar and the individual grammars of each feature in this module, and meet all other conformance requirements of style sheets as described in this module.
Partial implementations
So that authors can exploit the forward-compatible parsing rules to assign fallback values, CSS renderers must treat as invalid (and ignore as appropriate) any at-rules, properties, property values, keywords, and other syntactic constructs for which they have no usable level of support. In particular, user agents must not selectively ignore unsupported component values and honor supported values in a single multi-value property declaration: if any value is considered invalid (as unsupported values must be), CSS requires that the entire declaration be ignored.
Experimental implementations
To avoid clashes with future CSS features, the CSS2.1 specification reserves a prefixed syntax for proprietary and experimental extensions to CSS.
Prior to a specification reaching the Candidate Recommendation stage in the W3C process, all implementations of a CSS feature are considered experimental. The CSS Working Group recommends that implementations use a vendor-prefixed syntax for such features, including those in W3C Working Drafts. This avoids incompatibilities with future changes in the draft.
Non-experimental implementations
Once a specification reaches the Candidate Recommendation stage, non-experimental implementations are possible, and implementors should release an unprefixed implementation of any CR-level feature they can demonstrate to be correctly implemented according to spec.
To establish and maintain the interoperability of CSS across implementations, the CSS Working Group requests that non-experimental CSS renderers submit an implementation report (and, if necessary, the testcases used for that implementation report) to the W3C before releasing an unprefixed implementation of any CSS features. Testcases submitted to W3C are subject to review and correction by the CSS Working Group.
Further information on submitting testcases and implementation reports can be found from on the CSS Working Group’s website athttp://www.w3.org/Style/CSS/Test/. Questions should be directed to thepublic-css-testsuite@w3.org mailing list.
References
Normative References
Informative References
Index
- auto, 6.1
- * (type), [3](#typedef-basic-shape "section 3") * value for shape-outside, [6.1](#valuedef-basic-shape "section 6.1")
- border-box, 5
- * (type), [5](#typedef-box "section 5") * value for shape-outside, [6.1](#valuedef-box "section 6.1")
- circle(), 3.1
- closest-side, 3.1
- content-box, 5
- ellipse(), 3.1
- empty float area, 2
- farthest-side, 3.1
- , 3.1
- Float area, 1.4
- , 6.1
- inset(), 3.1
- , 6.3
- margin-box, 5
- , 6.2
- padding-box, 5
- , 6.3
- polygon(), 3.1
- reference box, 3
- , 3.1
- shape-image-threshold, 6.2
- shape-margin, 6.3
- shape-outside, 6.1
- , 3.1
- Wrap, 1.4
Property index
Name | Value | Initial | Applies to | Inh. | %ages | Media | Animatable | Computed value | |
---|---|---|---|---|---|---|---|---|---|
shape-outside | auto | [ | ] | auto | floats | no | visual | as specified for , otherwise no | ||
shape-image-threshold | 0.0 | floats | no | visual | as number | The same as the specified value after clipping the to the range [0.0,1.0] | |||
shape-margin | | | 0 | floats | no | visual | as length, percentage, or calc. | the absolute length |