# CSS Shapes Module Level 2

## Editor’s Draft, 1 January 1970

Specification Metadata

This version:
  https://drafts.csswg.org/css-shapes-2/
Latest published version:
  https://www.w3.org/TR/css-shapes-2/
Editors:
  Rossen Atanassov (Microsoft Corporation)
  Alan Stearns (Adobe Systems, Inc.)
Issue Tracking:
  GitHub Issues
Suggest an Edit for this Spec:
  GitHub Editor

Copyright © 1970 W3C® (MIT, ERCIM, Keio, Beihang). W3C liability, trademark and permissive document license rules apply.

## Abstract

This draft contains the features of CSS relating to wrapping content around and inside shapes. It (implicitly for now) includes and extends the functionality of CSS Shapes Level 1 [CSS-SHAPES]. The main points of extension compared to level 1 include additional ways of defining shapes, defining an exclusion area using a shape, and restricting an element’s content area using a shape.

CSS is a language for describing the rendering of structured documents (such as HTML and XML) on screen, on paper, etc.

## Status of this document

This is a public copy of the editors’ draft. It is provided for discussion only and may change at any moment. Its publication here does not imply endorsement of its contents by W3C. Don’t cite this document other than as work in progress.

GitHub Issues are preferred for discussion of this specification. When filing an issue, please put the text “css-shapes” in the title, preferably like this: “[css-shapes] …summary of comment…”. All issues and comments are archived, and there is also a historical archive.

This document was produced by the CSS Working Group.

This document was produced by a group operating under the 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 document is governed by the 1 March 2019 W3C Process Document.

## 1. Introduction

This section is not normative.

Level 1 of this specification defined properties to control the geometry of an element’s float area. This level defines how shapes apply to exclusions. It also includes a shape-inside property for applying a shape to an element’s content area. And finally it defines new ways of specifying shapes for all of these applications.

## 2. Terminology

Exclusion area

The area used for excluding inline flow content around an exclusion box. The exclusion area is equivalent to the border box for an exclusion box. This specification’s shape-outside property can be used to define arbitrary, non-rectangular exclusion areas. The shape-inside property also defines an exclusion area, but in this case it is the area outside the shape that inline content avoids.

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.

Content area

The content area is normally used for layout of the inline flow content of a box.

Issue-15089

shrink-to-fit circle / shape

## 3. Shapes

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

## 4. Basic Shapes

Add the final level 1 section.

### 4.1. Supported Shapes

Add the final level 1 section, with the following integrated.

    path() = path( [<fill-rule>,]? <string> )

  - <fill-rule> - The filling rule used to determine the interior of the path. See fill-rule property in SVG for details. Possible values are nonzero or evenodd. Default value when omitted is nonzero.
  - The <string> represents an SVG Path data string. The path data string must be conform to the grammar and parsing rules of SVG 1.1. The initial position is defined by the first “move to” argument in the path string. For the initial direction follow SVG 1.1.

Issue-16448

Should we revisit the decision to not allow SVG path syntax in the shape-inside, shape-outside properties

## 5. Referencing SVG shapes

An SVG shape can be referenced using the `url()` syntax. The shape can be any of the SVG basic shapes or a path element.

`

    <style>
    div {
    	height: 400px;
    	width: 400px;
    }
    .in-a-circle {
    	shape-outside: url(#circle_shape);
    }

    .in-a-path {
    	shape-outside: url(#path-shape);
    }

    </style>

    <svg ...>
    <circle id="circle_shape" cx="50%" cy="50%" r="50%" />
    <path id="path-shape" d="M 100 100 L 300 100 L 200 300 z" />
    </svg>

    <div class="around-a-circle">...</div>
    <div class="around-a-path">...</div>

`

## 6. Shapes from Image

Add the final level 1 section.

One suggestion is to define a shape based on an element’s rendered content. This could have security implications.

Another suggestion is to add something to an image() function that determines the relevant pixels to use (both for defining a shape and for display).

## 7. Shapes from Box Values

Add the final level 1 section.

## 8. Declaring Shapes

A shape can be 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 and an exclusion element’s exclusion area.

A shape can be declared with the shape-inside property, with possible modifications from the shape-padding property. The shape defined by the shape-inside and shape-padding properties defines an exclusion area that contributes to the element’s wrapping context. The shape-inside property applies to all block-level elements.

The red box illustrates an exclusion element’s content box, which is unmodified and subject to normal CSS positioning (here absolute positioning).

    <style type="text/css">
    .exclusion  {
        wrap-flow: both;
        position: absolute;
        top: 25%;
        left: 25%;
        width: 50%;
        height: 50%;
        shape-outside: circle(50% at 50% 50%);
        border: 1px solid red;
    }
    </style>

    <div style=”position: relative;”>
    <div class=”exclusion”></div>
    Lorem ipsum dolor sit amet...
    </div>

### 8.1. The shape-outside Property

Add the final level 1 section with the change that shape-outside applies to block-level elements and has an effect if the element is an exclusion.

### 8.2. The shape-inside Property

The shape-inside property adds one or more exclusion areas to the element’s wrapping context. This modifies the normal rectangular shape of the content area to a possibly non-rectangular wrapping area. The exclusion areas are defined by subtracting the shape from the element’s content area. Any part of the shape outside the element’s content area has no effect.

Name: | shape-inside
Value: | auto | outside-shape | [ <basic-shape> || shape-box ] | <image> | display
Initial: | auto
Applies to: | block-level elements
Inherited: | no
Percentages: | n/a
Computed value: | computed lengths for <basic-shape>, the absolute URI for <uri>, otherwise as specified
Canonical order: | per grammar
Animation type: | as defined for <basic-shape>, otherwise discrete

The values of this property have the following meanings:

auto
  The shape is computed based on the content box of the element.

outside-shape
  The shape is computed based on the shape defined by the shape-outside and shape-margin properties.

<basic-shape>
  The shape is computed based on the values of one of inset(), circle(), ellipse() or polygon().

<uri>
  If the <uri> references an SVG shape element, that element defines the shape. Otherwise, if the <uri> references an image, the shape is extracted and computed based on the alpha channel of the specified image.

  If the <uri> does not reference an SVG shape element or an image, the effect is as if the value auto had been specified.

display
  The shape is computed based on the shape of the display as described in css-round-display.

The shape-inside property applies to floats.

The shape-inside property may not apply on some elements such as elements with a computed display value of table.

Effect of shape-inside on inline content.

Overflow content avoids the exclusion area(s) added by shape-inside and shape-padding (as well as any other exclusion areas in the element’s wrapping context). In other words, overflow continues outside the rectangular bounds of the element.

Overflow interacting with exclusion areas defined by shape-inside and shape-padding.

improve the illustration above, using text to show overflow instead of greeked boxes.

When a shape-inside has a definite size (no percentages used in the shape’s definition) an auto-sized element should use the shape as a constraint in determining its maximum size.

### 8.3. The shape-image-threshold Property

Add the final level 1 section with the change that it applies to both shape-inside and shape-outside.

### 8.4. The shape-image-source-type Property

Should we add an alpha/luminance switch to determine which values we use from the shape-image source? This could just be a keyword on the shape-image-threshold property. Whatever we go with should be compatible with the alpha/luminance switch from mask sources.

### 8.5. The shape-margin property

Add the final level 1 section with the change that it applies to exclusions.

### 8.6. The shape-padding Property

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

Name: | shape-padding
Value: | <length>
Initial: | none
Applies to: | block-level elements
Inherited: | no
Percentages: | n/a
Computed value: | the absolute length
Canonical order: | per grammar
Animation type: | by computed value

A shape-padding creating an offset from a circlular shape-inside. The light blue rectangles represent inline content affected by the shape created by the padding.

Note: The shape-padding property only affects layout of content inside the element it applies to while the shape-margin property only affects layout of content outside the element.

## 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.

Advisements are normative sections styled to evoke special attention and are set apart from other normative text with `<strong class="advisement">`, like this: UAs MUST provide an accessible alternative.

### Conformance classes

Conformance to this specification is defined for three conformance classes:

style sheet
  A CSS 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.

### Requirements for Responsible Implementation of CSS

The following sections define several conformance requirements for implementing CSS responsibly, in a way that promotes interoperability in the present and future.

#### 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 property 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.

#### Implementations of Unstable and Proprietary Features

To avoid clashes with future stable CSS features, the CSSWG recommends following best practices for the implementation of unstable features and proprietary extensions to CSS.

#### Implementations of CR-level Features

Once a specification reaches the Candidate Recommendation stage, implementers should release an unprefixed implementation of any CR-level feature they can demonstrate to be correctly implemented according to spec, and should avoid exposing a prefixed variant of that feature.

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.

## Index

### Terms defined by this specification

- auto, in §8.2
- <basic-shape>, in §8.2
- Content area, in §2
- display, in §8.2
- evenodd, in §4.1
- Exclusion area, in §2
- <fill-rule>, in §4.1
- Float area, in §2
- nonzero, in §4.1
- outside-shape, in §8.2
- path(), in §4.1
- shape-inside, in §8.2
- shape-padding, in §8.6
- <string>, in §4.1
- <uri>, in §8.2

https://drafts.csswg.org/css-box-3/#border-box Referenced in:

- 2. Terminology

https://drafts.csswg.org/css-box-3/#margin-box Referenced in:

- 2. Terminology

https://drafts.csswg.org/css-display-3/#propdef-display Referenced in:

- 8.2. The shape-inside Property

https://drafts.csswg.org/css-display-3/#valdef-display-table Referenced in:

- 8.2. The shape-inside Property

https://drafts.csswg.org/css-shapes-1/#typedef-fill-rule Referenced in:

- 4.1. Supported Shapes (2)

https://drafts.csswg.org/css-shapes-1/#funcdef-circle Referenced in:

- 8.2. The shape-inside Property

https://drafts.csswg.org/css-shapes-1/#funcdef-ellipse Referenced in:

- 8.2. The shape-inside Property

https://drafts.csswg.org/css-shapes-1/#funcdef-inset Referenced in:

- 8.2. The shape-inside Property

https://drafts.csswg.org/css-shapes-1/#funcdef-polygon Referenced in:

- 8.2. The shape-inside Property

https://drafts.csswg.org/css-shapes-1/#propdef-shape-margin Referenced in:

- 8. Declaring Shapes (2)
- 8.5. The shape-margin property
- 8.6. The shape-padding Property

https://drafts.csswg.org/css-shapes-1/#propdef-shape-outside Referenced in:

- 2. Terminology (2)
- 8. Declaring Shapes (2)
- 8.1. The shape-outside Property

https://drafts.csswg.org/css-values-3/#length-value Referenced in:

- 8.6. The shape-padding Property

https://drafts.csswg.org/css-values-3/#string-value Referenced in:

- 4.1. Supported Shapes (2)

https://drafts.csswg.org/css-values-4/#comb-comma Referenced in:

- 4.1. Supported Shapes

https://drafts.csswg.org/css-values-4/#mult-opt Referenced in:

- 4.1. Supported Shapes

https://drafts.csswg.org/css-values-4/#comb-one Referenced in:

- 8.2. The shape-inside Property (2) (3) (4)

https://drafts.csswg.org/css-values-4/#comb-any Referenced in:

- 8.2. The shape-inside Property

https://drafts.csswg.org/css-images-3/#typedef-image Referenced in:

- 8.2. The shape-inside Property

### Terms defined by reference

- [css-box-3] defines the following terms:
  - border box
  - margin box
- [css-display-3] defines the following terms:
  - display
  - table
- [CSS-SHAPES] defines the following terms:
  - <fill-rule>
  - circle()
  - ellipse()
  - inset()
  - polygon()
  - shape-margin
  - shape-outside
- [css-values-3] defines the following terms:
  - <length>
  - <string>
- [css-values-4] defines the following terms:
  - ,
  - ?
  - |
  - ||
- [css3-images] defines the following terms:
  - <image>

## References

### Normative References

[CSS-BOX-3]
  Elika Etemad. CSS Box Model Module Level 3. 18 December 2018. WD. URL: https://www.w3.org/TR/css-box-3/
[CSS-DISPLAY-3]
  Tab Atkins Jr.; Elika Etemad. CSS Display Module Level 3. 28 August 2018. CR. URL: https://www.w3.org/TR/css-display-3/
[CSS-SHAPES]
  Vincent Hardy; Rossen Atanassov; Alan Stearns. CSS Shapes Module Level 1. 20 March 2014. CR. URL: https://www.w3.org/TR/css-shapes-1/
[CSS-VALUES-3]
  Tab Atkins Jr.; Elika Etemad. CSS Values and Units Module Level 3. 31 January 2019. CR. URL: https://www.w3.org/TR/css-values-3/
[CSS-VALUES-4]
  Tab Atkins Jr.; Elika Etemad. CSS Values and Units Module Level 4. 31 January 2019. WD. URL: https://www.w3.org/TR/css-values-4/
[CSS3-IMAGES]
  Elika Etemad; Tab Atkins Jr.. CSS Image Values and Replaced Content Module Level 3. 17 April 2012. CR. URL: https://www.w3.org/TR/css3-images/
[RFC2119]
  S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Best Current Practice. URL: https://tools.ietf.org/html/rfc2119

## Property Index

Name | Value | Initial | Applies to | Inh. | %ages | Animation type | Canonical order | Computed value
--- | --- | --- | --- | --- | --- | --- | --- | ---
shape-inside | auto | outside-shape | [ <basic-shape> || shape-box ] | <image> | display | auto | block-level elements | no | n/a | as defined for <basic-shape>, otherwise discrete | per grammar | computed lengths for <basic-shape>, the absolute URI for <uri>, otherwise as specified
shape-padding | <length> | none | block-level elements | no | n/a | by computed value | per grammar | the absolute length

## Issues Index

One suggestion is to define a shape based on an element’s rendered content. This could have security implications. ↵
Another suggestion is to add something to an image() function that determines the relevant pixels to use (both for defining a shape and for display). ↵
improve the illustration above, using text to show overflow instead of greeked boxes. ↵
#content-area Referenced in:

- 2. Terminology

#valdef-path-nonzero Referenced in:

- 4.1. Supported Shapes (2)

#valdef-path-evenodd Referenced in:

- 4.1. Supported Shapes

#propdef-shape-inside Referenced in:

- 1. Introduction
- 2. Terminology
- 8. Declaring Shapes (2) (3)
- 8.2. The shape-inside Property (2) (3) (4) (5) (6)

#valdef-shape-inside-auto Referenced in:

- 8.2. The shape-inside Property (2)

#valdef-shape-inside-outside-shape Referenced in:

- 8.2. The shape-inside Property

#typedef-basic-shape Referenced in:

- 8.2. The shape-inside Property (2) (3)

#typedef-uri Referenced in:

- 8.2. The shape-inside Property

#valdef-shape-inside-display Referenced in:

- 8.2. The shape-inside Property

#propdef-shape-padding Referenced in:

- 8. Declaring Shapes (2)
- 8.2. The shape-inside Property (2)
- 8.6. The shape-padding Property (2) (3) (4)