Learn to maintain a consistent stroke width in After Effects when scaling shape layers, apply the "Maintain Stroke Width" expression to the Stroke Width property. Alternatively, adjust the scale within the "Transform Shape" property of the shape layer for the same effect.
Hey there, fellow motion graphics nerds! I’m stoked to dive into one of those little After Effects tricks that can save you a ton of headaches: maintaining stroke width when scaling shape layers. I’ve been cutting and animating videos for over a decade, and let me tell you, this is one of those things I wish I’d known earlier in my After Effects journey. If you’ve ever scaled a shape layer and watched your carefully crafted stroke turn into a noodle or a razor-thin line, you know the pain. Today, I’m walking you through how to use expressions to keep your stroke width consistent, step-by-step, like we’re chilling in my editing suite. Plus, I’ll throw in some killer Envato Elements templates that can level up your projects. Let’s get into it!
Picture this: you’re working on a slick logo animation or a clean motion graphics piece. You’ve got a shape layer—a circle, a line, maybe a fancy geometric design—with a perfect 5-pixel stroke. You scale it up to make it pop, and suddenly, that stroke is a chunky 10-pixel mess. Or worse, you scale it down, and the stroke is so thin it’s practically invisible. Frustrating, right? This happens because After Effects scales everything proportionally by default, including the stroke width. But sometimes, you want that stroke to stay exactly the same, no matter how much you stretch or shrink the layer.
That’s where the “Maintain Stroke Width” expression comes in. It’s like telling After Effects, “Hey, keep my stroke chill while I mess with the scale.” I’ve used this trick in countless projects, from explainer videos to title sequences, and it’s a game-changer. Let’s break down how to make it happen.
Alright, let’s start with the basics. Open up After Effects—I’m assuming you’re already comfy with the interface, but if not, no sweat, I’ll keep it simple. Create a new composition (I usually go with 1920x1080, 30fps, but you do you). Grab the Pen tool, Rectangle tool, or whatever shape tool you’re feeling, and draw a shape on a new shape layer. For this tutorial, let’s say we’re working with a simple circle (Ellipse tool, hold Shift to keep it perfect).
Once your shape is drawn, expand the layer in the timeline by clicking the little triangle next to its name. Then, dive into the “Contents” section, find your shape group (like “Ellipse 1”), and expand that to get to the “Stroke 1” property. You’ll see “Stroke Width” sitting there, probably set to something like 5 pixels. That’s our target.
Now, scale the layer up or down using the Transform properties (hit S to bring up Scale). Notice how the stroke gets thicker or thinner? That’s what we’re here to fix.
Here’s where the magic happens. To keep that stroke width consistent, we’re going to use an expression on the Stroke Width property. Don’t worry if expressions make you nervous—I used to avoid them like the plague, but this one’s super straightforward.
value / length(toComp([0,0]), toComp([0.7071,0.7071])) || 0.001
Let me break down what this does, because I know expressions can look like alien code at first. The value part refers to the original stroke width you set (say, 5 pixels). The length(toComp([0,0]), toComp([0.7071,0.7071])) bit calculates how much the layer is scaled by comparing two points in the composition space. Dividing the stroke width by this scale factor adjusts it to stay visually consistent. The || 0.001 at the end is a safety net—it prevents the stroke from disappearing if the scale goes to zero (which would otherwise break the expression).
Now, try scaling your shape layer again. Boom! The stroke stays rock-solid at 5 pixels (or whatever you set it to), no matter how big or small you go. I remember the first time I got this working on a client project—it felt like I’d unlocked a cheat code.
Okay, here’s where things get a bit spicy. If you scale your shape non-uniformly (different values for X and Y), the stroke might still act a little funky. Why? The expression we just used assumes uniform scaling. If you’re stretching your shape more in one direction, the stroke width can look uneven.
Here’s a pro tip I picked up after some trial and error: you can tweak the expression to average the X and Y scale values for a more balanced result. Try this modified expression:
value / ((transform.scale[0] + transform.scale[1]) / 200) || 0.001
This one takes the average of the X (transform.scale[0]) and Y (transform.scale[1]) scale values (divided by 200 to convert percentages to a decimal) and adjusts the stroke accordingly. It’s not perfect for extreme stretches, but it’s a solid fix for most cases. I’ve used this on projects where I needed to animate a logo that squashes and stretches without the stroke going haywire.
If expressions aren’t your jam, there’s another way to maintain stroke width without diving into code. Instead of scaling the entire shape layer, you can scale the shape itself within the layer’s “Transform Shape” property. Here’s how:
This keeps the stroke width unaffected because the stroke is applied after the shape’s transformation. It’s a manual workaround, but I’ve used it in a pinch when I didn’t want to mess with expressions. The downside? It’s less flexible if you’re animating multiple properties or working with complex groups. Still, it’s a good trick to have in your back pocket.
Now that you’ve got the stroke width thing locked down, let’s talk about taking your motion graphics to the next level. I’m a huge fan of Envato Elements for grabbing After Effects templates that save time and look pro. Since you’re probably working on projects that involve shape layers and strokes (like logo reveals or title animations), here are a few templates that pair perfectly with the maintain stroke width trick:
These templates are awesome for explainer videos, especially if you’re animating clean, line-based graphics. They use shape layers heavily, so you can apply the maintain stroke width expression to keep those lines crisp when scaling. I’ve used similar templates for tech clients, and dropping in the expression makes animations feel super polished. Check it out on Envato Elements.
If you’re working on text animations with outlined strokes (think neon or handwritten effects), this collection is a goldmine. The templates are universal, so you can easily add the stroke width expression to keep outlines consistent. I’ve used these for social media promos, and clients love the clean look. Available on Envato Elements.
This bold, colorful template is great for showcasing products with dynamic shape animations. The modular structure means you can tweak scale without worrying about stroke issues if you apply our expression. I’ve leaned on this one for e-commerce projects—it’s a real time-saver. Find it on Envato Elements.
These templates are a lifesaver when you’re on a tight deadline. Pair them with the stroke width expression, and you’re delivering pro-level work without breaking a sweat.
Let’s kick it up a notch. The maintain stroke width expression is awesome, but it really shines when you combine it with other After Effects features like Trim Paths. Say you want to animate your stroke to draw on or reveal your shape (super common for logo animations). Here’s how to make it work:
I used this combo on a recent project for a startup’s logo reveal. The client wanted the logo to scale up dramatically while the stroke drew on, and the expression kept everything looking sharp. It’s one of those moments where you pat yourself on the back for knowing your craft.
Even with all my years in After Effects, I still hit snags sometimes. Here are a couple of common issues and how to fix them:
So, where does this trick come in handy? Honestly, everywhere. I’ve used it for:
One of my favorite projects was an explainer video for a fintech company. They had a bunch of animated charts with line graphs that needed to scale dynamically. Without the maintain stroke width expression, those lines would’ve looked all over the place. Instead, everything stayed crisp, and the client was thrilled.
If you’re feeling adventurous, you can take the expression further. For example, you can tie the stroke width to a slider control for more flexibility. Here’s how:
effect("Stroke Width")("Slider") / length(toComp([0,0]), toComp([0.7071,0.7071])) || 0.001
Now, you can adjust the stroke width dynamically using the slider, and it’ll still stay consistent when scaling. I’ve used this setup for templates I share with my team, so they can tweak stroke widths without touching the expression.
There you have it, folks—a dead-simple way to maintain stroke width in After Effects using expressions. Whether you’re animating logos, crafting explainer videos, or building out motion graphics, this trick will keep your strokes looking sharp and professional. Pair it with some dope Envato Elements templates like the ones I mentioned, and you’re ready to crank out high-quality work in half the time.
I’ve been at this for years, and little hacks like this are what make After Effects so fun to work with. Got questions or want to share how you’re using this expression? Hit me up in the comments or on social—I love geeking out over this stuff. Now go make something awesome!
Browse Graphics, Mockups, Brushes & More!
Search