CSS Shapes Module Level 1

W3C First Public Working Draft 20 June 2013

This version:
Latest version:
Editor's Draft:
Vincent Hardy, Adobe Systems, Inc.,
Rossen Atanassov, Microsoft Corporation,
Alan Stearns, Adobe Systems, Inc.,
Issues List:
in Bugzilla
www-style@w3.org with subject line “[css-shapes] … message topic …” (archives)


CSS Shapes control the geometric shapes used for wrapping inline flow content outside an element. 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.

Future levels of CSS Shapes will allow use of shapes on elements other than floats

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 First Public 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 (see instructions) 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.

Table of contents

1. Introduction

This section is not normative.

This specification defines properties to control the geometry of an element's float area.

2. Definitions

Float area

The area used for wrapping content around a float element. By default, the float area is the float element's margin box. This specification's ‘shape-outside’ property can be used to define arbitrary, non-rectangular float areas.

3. Shapes

Shapes define arbitrary geometric contours around which inline content flows. The shape-outside property defines the float area for a float.

If a user agent implements both CSS Shapes and CSS Exclusions, the shape-outside property defines the exclusion area for an exclusion.

A future level of CSS Shapes will define a shape-inside property, which will define a shape to wrap content within the element.

3.1. Relation to the box model and float behavior

While the boundaries used for wrapping inline flow content outside an float can be defined using shapes, the actual box model does not change. If the element has specified margins, borders or paddings they will be computed and rendered according to the [CSS3BOX] module.

Float positioning is an exception. If a float has an outside shape, its positioning is resolved as defined in [CSS21] but the outside shape's bounding box is used in lieu of the float's margin box.

In the following example the left and right floating div elements specify a triangular shape using the ‘shape-outside’ property.

<div style="text-align:center;">
      <div id="float-left"></div>
      <div id="float-right"></div>
      Sometimes a web page's text content appears to be
      funneling your attention towards a spot on the page
      to drive you to follow a particular link.  Sometimes
      you don't notice.

<style type="text/css">
#float-left {
      shape-outside: polygon(0,0 100%,100% 0,100%);
      float: left;
      width: 40%;
      height: 12ex;

#float-right {
      shape-outside: polygon(100%,0 100%,100% 0,100%);
      float: right;
      width: 40%;
      height: 12ex;
Using the shape-outside property with a float

3.2. Basic Shapes

Shapes can be specified using syntax similar to SVG's basic shapes. The definitions use <length> type and the <percentage> types (see [CSS3VAL]). Percentages are resolved from the computed value of the box-sizing property [CSS3UI] on the element to which the property applies. For the radius r of the circle shape, a percentage value is resolved as specified in the SVG recommendation (see [SVG11]). Path styling like stroking is not considered part of the specified shape.

3.2.1. Supported Shapes

The following basic shapes are supported.

rectangle([<length>|<percentage>]{4} [ curve [<length>|<percentage>]{1,2} ]? )
inset-rectangle([<length>|<percentage>]{4} [ curve [<length>|<percentage>]{1,2} ]? )
polygon([<fill-rule>,]? [<length>|<percentage>]{2}#)

The UA will close a polygon by connecting the last vertex with the first vertex of the list.

The values for corner radii on rectangle or inset-rectangle are determined implicitly if either the rx or ry values are not specified, or are specified but with invalid values. If neither rx nor ry are properly specified, the values are 0 for both. If only one value is properly specified, that value is used for both. And if the values cause any of the curves to overlap, the solution for overlapping curves from CSS Backgrounds and Borders [CSS3BG] is used to avoid the overlap.

3.2.2. Interpolation of Basic Shapes

For interpolating between one basic shape and a second, the rules described below are applied.

3.3. Shapes from Image


Address security concern with automatic shape extractions for images

Another way of defining shapes is by specifying a source image 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.5.

For animated raster image formats (such as GIF), 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 and specifies a value of 35 pixels for the ‘shape-margin’ property.

  <img id="CSSlogo" src="CSS-logo1s.png"/>
  blah blah blah blah...

  #CSSlogo {
    float: left;
    shape-outside: url("CSS-logo1s.png");
    shape-image-threshold: 0.1;
    shape-margin: 35px;

The image needs two references to the image because this example uses the same image

  1. to render it
  2. as a shape defining the float area of the image

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 and the 35px shape-margin is visible between that line and the edges of each individual line of the paragraph.

It's then possible to affect where the lines of the paragraph start in three ways:

  1. Changing the value of the ‘shape-margin’ property
  2. Changing the value of the ‘shape-image-threshold’ property
  3. Modifying the alpha channel in the image
A float shape around an image using its alpha-channel with a 35 pixels shape-margin

A float shape around an image using its alpha-channel with a 35 pixels shape-margin

3.4. 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's float area.

3.4.1. The ‘shape-outside’ Property

Name: shape-outside
Value: auto | <basic-shape> | <uri>
Initial: auto
Applies to: floats
Inherited: no
Percentages: N/A
Media: visual
Computed value: computed lengths for <basic-shape>, the absolute URI for <uri>, otherwise as specified

The values of this property have the following meanings:

The float area uses the margin box as normal.
The shape is computed based on the values of one of ‘rectangle’, ‘inset-rectangle’, ‘circle’, ‘ellipse’ or ‘polygon’.
If the <uri> references an image, which is CORS-same-origin, the shape is extracted and computed based on the alpha channel of the specified image. If the <uri> does not reference an image or if it references an image which is not CORS-same-origin, the effect is as if the value ‘auto’ had been specified.

3.4.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 all the pixels that are more than 50% transparent define the path of the shape.

Name: shape-image-threshold
Value: <alphavalue>
Initial: 0.5
Applies to: floats
Inherited: no
Percentages: alpha channel of the image specified by <uri>
Media: visual
Computed value: The same as the specified value after clipping the <alphavalue> to the range [0.0,1.0].

The values of this property have the following meanings:

A <number> value used to set the threshold used for extracting a shape from an image. Any values outside the range 0.0 (fully transparent) to 1.0 (fully opaque) will be clamped to this range.

3.4.3. The ‘shape-margin’ property

The ‘shape-margin’ property adds a margin to a shape-outside. This defines a new shape where every point is the specified distance from the shape-outside. This property takes on positive values only.

Name: shape-margin
Value: <length>
Initial: 0
Applies to: floats
Inherited: no
Percentages: N/A
Media: visual
Computed value: the absolute length

A ‘shape-margin’ creating an offset from a circlular shape-outside. The blue rectangles represent inline content affected by the shape created by the margin.

Example of a shape-margin offset

4. 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
A CSS style sheet.
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 CSS 2.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 at http://www.w3.org/Style/CSS/Test/. Questions should be directed to the public-css-testsuite@w3.org mailing list.


This specification is made possible by input from Andrei Bucur, Alexandru Chiculita, 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.


Normative references

Bert Bos; et al. Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification. 7 June 2011. W3C Recommendation. URL: http://www.w3.org/TR/2011/REC-CSS2-20110607
Bert Bos; Elika J. Etemad; Brad Kemper. CSS Backgrounds and Borders Module Level 3. 24 July 2012. W3C Candidate Recommendation. (Work in progress.) URL: http://www.w3.org/TR/2012/CR-css3-background-20120724/
Bert Bos. CSS basic box model. 9 August 2007. W3C Working Draft. (Work in progress.) URL: http://www.w3.org/TR/2007/WD-css3-box-20070809
Tantek Çelik. CSS Basic User Interface Module Level 3 (CSS3 UI). 17 January 2012. W3C Working Draft. (Work in progress.) URL: http://www.w3.org/TR/2012/WD-css3-ui-20120117/
Håkon Wium Lie; Tab Atkins; Elika J. Etemad. CSS Values and Units Module Level 3. 4 April 2013. W3C Candidate Recommendation. (Work in progress.) URL: http://www.w3.org/TR/2013/CR-css3-values-20130404/
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. Internet RFC 2119. URL: http://www.ietf.org/rfc/rfc2119.txt
Erik Dahlström; et al. Scalable Vector Graphics (SVG) 1.1 (Second Edition). 16 August 2011. W3C Recommendation. URL: http://www.w3.org/TR/2011/REC-SVG11-20110816/

Other references


Property index

Property Values Initial Applies to Inh. Percentages Media
shape-image-threshold <alphavalue> 0.5 floats no alpha channel of the image specified by <uri> visual
shape-margin <length> 0 floats no N/A visual
shape-outside auto | <basic-shape> | <uri> auto floats no N/A visual

Change Log

Since May 3rd 2012

Since December 13th 2011