Creative text flows using CSS shapes
Tags: featuredposts, css
Published: 2020-04-22 16:08:40

---
title: Creative text flows using CSS shapes
published: true
date: 2020-03-25 17:30:05 UTC
tags: Featured Posts,css
canonical_url: https://blog.logrocket.com/creative-text-flows-using-css-shapes/
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/2lpjt1w5s8sbhi1y24gz.png
---
**Written by [Abbey Fitzgerald](https://blog.logrocket.com/author/abbeyjfitzgerald/)**✏️

Thinking back to many years ago and how I started my design career, I remember creating creative text flows in Adobe InDesign. Beginning as a print designer, I worked a lot in that page layout program. When working on layouts, sometimes text would flow around an image or “wrap” around a shape. This is referred to as “text wrap” in the print world. That’s not the term used on the web, but this same kind of idea is available with CSS styling.

![example of aligned text in magazine](https://i0.wp.com/blog.logrocket.com/wp-content/uploads/2020/03/exampleofaligntext.jpg?resize=730%2C334&ssl=1)

Content is key on any website. There are a lot of best practices when it comes to web typography but the most important design rule is to keep typography legible and optimized for the best viewing experience.

With great power comes great responsibility. When designing and planning for the typography and flow of text, it’s important to be mindful of the reading experience for your users. Just because you can do something “fun and different”, doesn’t mean you necessarily should if it is distracting or impacts the legibility in a negative way. Legibility is the first priority, but your creativity doesn’t have to be limited if you want to break the grid a bit. Let’s take a look at how creative text flows can be incorporated into your designs.

[![LogRocket Free Trial Banner](https://i0.wp.com/blog.logrocket.com/wp-content/uploads/2017/03/f760c-1gpjapknnuyhu8esa3z0jga.png?resize=1200%2C280&ssl=1)](https://logrocket.com/signup/)

## How can shapes and text be integrated?

It’s been some time, but I recall reading articles and hearing designers say, “all websites look the same”. It was probably a few years ago and now I don’t see things being completely uniform as I browse the web.

I bring this up because there is more flexibility now since browsers have become more advanced. Websites appear unique and interesting because designers are utilizing unique graphics, animations, and things like creative text flows. The good news is, using CSS for styling allows for flexibility and you can do interesting things with the text flow in your designs. Simple shapes and clip paths are ways to get creative with text flows.

## Shapes

Simple shapes are pretty straightforward when it comes to circles, ellipses, and rectangles. What’s being done here is the shape-outside property being utilized to reflow the text. This property is what allows us to break away from the rectangular shape that we’re used to. It will allow text to wrap around other shapes.

![text align around shapes](https://i0.wp.com/blog.logrocket.com/wp-content/uploads/2020/03/textalignshapes.jpg?resize=730%2C190&ssl=1)<figcaption id="caption-attachment-16094">We’re used to seeing squares and rectangles on the web when it comes to text flow</figcaption>

## Simple shape

As a simple example, I want my text to wrap around a circle. It adds some visual interest to the long text and something like this is pretty easy to style. This is one of those cases, where it’s easiest to learn by doing. Using the shape-outside property, the text flows around a circle, rather than rectangles that we’re used to seeing. The basic idea looks like this:

![text aligen with circle](https://i1.wp.com/blog.logrocket.com/wp-content/uploads/2020/03/circlecodepen.jpg?resize=932%2C264&ssl=1)

Here is an example on CodePen:

{% codepen https://codepen.io/abbeyjfitzgerald/pen/MWwGmoy %}

**Note** : In order for the shape-outside property to work, you need to include a float and set a height and width. In the example above, a width and height of 200px has been set and there is a left float declared. One thing to think about, since the float determines which side of the shape has the wrapping, there wouldn’t be wrapping around the entire shape.

Instead of a circle, maybe you’d like to use an ellipse as your shape. Keep in mind, it’s a pretty quick fix to adjust the circle to make it into an ellipse. One dimension is elongated compared to the other. Depending on the ellipse, either the horizontal or vertical axis is larger. I’m a bit out of geometry practice, but rx is the radius value on the x-axis. Ry is the value on the y-axis.

You may see something like clip-path: ellipse(100px 200px at 50% 50%) if you want to use an ellipse. There are two sets of numbers here. We know the first set specifies the dimensions, but what is the second set of numbers? Those are the cx and cy. They are the coordinates of the ellipse’s center.

![text aligned around adjusted ellipse](https://i0.wp.com/blog.logrocket.com/wp-content/uploads/2020/03/ovalshape.jpg?resize=730%2C231&ssl=1)<figcaption id="caption-attachment-16102">See how the coordinates can adjust the placement: ellipse(100px 200px at 20% 30%) compared to ellipse(100px 200px at 50% 50%)</figcaption>

{% codepen https://codepen.io/abbeyjfitzgerald/pen/OJVZmpq %}

## Using a .png file

A simple circle is pretty straightforward but keep in mind that the shape-outside property also works with .png images. To utilize .png files, it’s easiest to combine the image with a shape. This plant image is combined with a circle so the text best flows around it. This is where shape-margin comes into play.

![text wrapped around a png image of a plant](https://i0.wp.com/blog.logrocket.com/wp-content/uploads/2020/03/textwraparoundpng.jpg?resize=730%2C337&ssl=1)<figcaption id="caption-attachment-16106">This example uses shape-outside with margin-box. It’s important to know that the margin-box is used by default. It’s good to have a reminder of the box model, they can be added to the end of the shape-end. Margin-box and border-box are typically used.</figcaption>

Here is the example on CodePen (try adjusting the size and shape-margin to see what happens):

{% codepen https://codepen.io/abbeyjfitzgerald/pen/yLNjbwg %}

## Shape margin

This example has some organic shapes in the leaves, so it looks better visually if there is some margin between the image and the text. Shape-margin defines a shape so it doesn’t have to do directly with the text flow, but it has to do with spacing. You may have noticed in a couple of the examples, the text was close to the shape. That may or may not be what you are going for. It’s nice to have some breathing room between the two, so the good news is that there is a way to add some space.

## Float

Having a float defined is important because it is needed for the wrapping. It’s easy to experiment with this, but remember that floats require opposite thinking. If this image of the plant is floated right, the wrapping happens on the left side of the image. You’ll need to set dimensions of the image as well, so remembering to set a height/width is necessary.

### Creating a pull-quote with content-box

It’s a fairly simple concept, but the terminology can be a bit confusing since we’re not relying on a shape like we did in the examples above. Think of a design element like pull quotes. Sometimes these are designed to have the article text wrapping around them. It’s a good way to integrate article text and key quotes (common in magazines). This is certainly an option on the web. It just takes a bit of styling.

The shape-outside is going to look a bit different here. Content-box refers to the amount of content that the pull quote includes and the outside content will wrap around it. There isn’t a defined shape, so it is using the standard rectangle. Like the other examples, the width, height, and float are necessary when using shape-outside.

```jsx
.pull-quote{
  width: 200px;
  height: 200px;
  shape-outside: content-box;
  margin-top: 35px;
  float: right;
}
```

![example of text aligned around a pull quote](https://i0.wp.com/blog.logrocket.com/wp-content/uploads/2020/03/s_231834B156F7EEED4EF6DC2E6953C8DF6DFD49B0A9DCE68294DE906693F57660_1584426547380_pull-quote-example.jpg?resize=730%2C391&ssl=1)

Here is the CodePen:

{% codepen https://codepen.io/abbeyjfitzgerald/pen/MWwGxyv %}

## Complex shapes

### Clip paths

When working on these examples, I found [Clippy](https://bennettfeely.com/clippy/), the CSS clip path maker, to be a huge help when getting the base shape established. There may be some cases where you want to work with some more complex shapes like polygons. For things like polygons, you’ll be working with clip-paths. It might be kind of intimidating to see a lot of values when you see something like clip-path: polygon(50% 0%, 90% 20%, 100% 60%, 75% 100%, 25% 100%, 0% 60%, 10% 20%) , but using a tool like Clippy really helps. This is a pretty simple heptagon, but this same technique can be used for more complex paths.

![text wrap around a polygon](https://i2.wp.com/blog.logrocket.com/wp-content/uploads/2020/03/textwraparoundpolygon.jpg?resize=730%2C478&ssl=1)

Here is the example on CodePen:

{% codepen https://codepen.io/abbeyjfitzgerald/pen/eYNrXMr %}

It may not take very complex shapes to do this but think about combining shapes. Since content wraps around the shape on the opposite side designated by the float, you can have two floated shapes and text between them. It offers an interesting effect.

## Browser support

It’s always important to check browser support when using CSS shapes. [Can I use](https://caniuse.com/) is always a helpful resource. The good news is, these text flows are design enhancements. Content is always the main focus so users should still be able to access the text whether the flow is wrapping or not.

## Conclusion

CSS shapes can be simple or complex. Now that you have the basics of text flows and CSS shapes, you can incorporate some of these concepts into your web layouts.

* * *
## Is your frontend hogging your users' CPU?

As web frontends get increasingly complex, resource-greedy features demand more and more from the browser. If you’re interested in monitoring and tracking client-side CPU usage, memory usage, and more for all of your users in production, [try LogRocket.](https://logrocket.com/signup/) 

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/403rye2ptzx994uhktk1.png)

[LogRocket](https://logrocket.com/signup/) is like a DVR for web apps, recording everything that happens in your web app or site. Instead of guessing why problems happen, you can aggregate and report on key frontend performance metrics, replay user sessions along with application state, log network requests, and automatically surface all errors.

Modernize how you debug web apps — [Start monitoring for free.](https://logrocket.com/signup/)
* * *

The post [Creative text flows using CSS shapes](https://blog.logrocket.com/creative-text-flows-using-css-shapes/) appeared first on [LogRocket Blog](https://blog.logrocket.com).