CSS Shape-outside

CSS (Cascading Style Sheets) is a powerful tool used for styling and formatting web pages. One of the interesting features of CSS is the shape-outside property, which allows you to wrap text around non-rectangular shapes. In this article, we will explore the shape-outside property in detail and provide examples to help you understand its usage.

The shape-outside property is used to define the shape that an element should take when wrapping text around it. This property works in conjunction with the float property, which is used to position elements to the left or right of the text flow. By combining these two properties, you can create visually appealing layouts with text flowing around various shapes.

Let’s start by looking at some basic shapes that can be used with the shape-outside property:

1. Circle:
The circle shape is defined using the circle() function. The radius of the circle is specified as the parameter. For example, to create a circle with a radius of 100 pixels, you can use the following CSS:

“`css
.shape {
float: left;
width: 200px;
height: 200px;
shape-outside: circle(100px);
}
“`

2. Ellipse:
Similar to a circle, an ellipse can also be created using the ellipse() function. The parameters represent the horizontal and vertical radii. Here’s an example of creating an ellipse with a width of 200 pixels and a height of 100 pixels:

“`css
.shape {
float: left;
width: 200px;
height: 200px;
shape-outside: ellipse(100px 50px);
}
“`

3. Polygon:
The polygon shape is defined by specifying the coordinates of its vertices. Each coordinate is separated by a space. Here’s an example of creating a triangular shape:

“`css
.shape {
float: left;
width: 200px;
height: 200px;
shape-outside: polygon(0 0, 0 200px, 200px 200px);
}
“`

4. Path:
The path shape allows you to define custom shapes using SVG (Scalable Vector Graphics) path syntax. This provides a more flexible way to create complex shapes. Here’s an example of creating a custom shape using a path:

“`css
.shape {
float: left;
width: 200px;
height: 200px;
shape-outside: path(‘M0,0 L0,200 L200,200 L200,0 L100,100 Z’);
}
“`

It’s important to note that the shape-outside property only affects how text wraps around the specified shape and does not actually change the shape of the element itself. To see the effect of the shape-outside property, you need to combine it with the float property and ensure that the element has a non-zero width and height.

In addition to the basic shapes mentioned above, you can also use images as shapes with the shape-outside property. By referencing an image file, you can create text wrapping around the contours of the image. Here’s an example of using an image as a shape:

“`css
.shape {
float: left;
width: 200px;
height: 200px;
shape-outside: url(‘path/to/image.png’);
}
“`

In conclusion, the shape-outside property in CSS allows you to create visually appealing layouts by wrapping text around non-rectangular shapes. By combining the shape-outside property with the float property, you can achieve complex text wrapping effects. Whether you want to create circles, polygons, custom paths, or use images as shapes, CSS provides the flexibility to achieve your desired layout.

Experiment with different shapes and see how they can enhance the visual appeal of your web pages. With the shape-outside property, you can create unique and engaging designs that capture the attention of your website visitors.

Scroll to Top