Maintain Stroke Width After Effects Expression - A Video Editor’s Guide

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.

July 7, 2025

Join MILLIONS of users who have unleashed their true potential with Envato's new templates

Unlock Unlimited Creative Assets

Keep Your Strokes Sharp: A Video Editor’s Guide to Maintaining Stroke Width in After Effects

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!

After Effects Expression templates At Envato

Why Stroke Width Matters

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.

Step 1: Setting Up Your Shape Layer

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.

Step 2: Applying the Maintain Stroke Width Expression

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.

  1. Access the Stroke Width Property: In the timeline, under your shape layer, navigate to Contents > Ellipse 1 > Stroke 1 > Stroke Width.
  2. Activate the Expression: Hold down Alt (or Option on Mac) and click the stopwatch next to “Stroke Width.” This opens up a text box for the expression.
  3. Paste the Expression: Drop in this bad boy:

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.

Step 3: Handling Non-Uniform Scaling

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.

Step 4: Alternative Method (No Expressions)

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:

  1. Go to your shape layer in the timeline.
  2. Expand Contents > Ellipse 1 > Transform: Ellipse 1 (or whatever your shape is called).
  3. Adjust the Scale property here instead of the layer’s main Transform scale.

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.

Step 5: Leveling Up with Envato Templates

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:

1. Development Animation

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.

2. After Effects Text Templates

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.

3. Product Promo

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.

Step 6: Animating with Trim Paths

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:

  1. Go to your shape layer and expand Contents > Ellipse 1.
  2. Click the “Add” button (the little arrow next to the shape name) and select “Trim Paths.”
  3. Animate the End or Start properties to create that drawing effect. Add keyframes to make the stroke “write on” over time.
  4. Since the maintain stroke width expression is already on the Stroke Width property, your animated stroke will stay consistent as you scale the layer.

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.

Step 7: Troubleshooting Tips

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:

  • Expression Errors: If you get an error like “division by zero,” it’s likely because your layer’s scale hit zero. That’s what the || 0.001 in the expression is for—it should prevent this, but double-check your scale keyframes.
  • Non-Uniform Scaling Issues: If the stroke still looks off with non-uniform scaling, try the averaged expression I shared earlier. If that’s not cutting it, consider pre-composing your shape layer and applying the expression there.
  • Performance Lag: Expressions are light, but if you’re working with a ton of shape layers, After Effects can get sluggish. Try pre-rendering your shape animations if you’re finalizing a comp.

Step 8: Real-World Applications

So, where does this trick come in handy? Honestly, everywhere. I’ve used it for:

  • Logo Animations: Keeping strokes consistent when a logo scales up or down.
  • Motion Graphics: Creating clean, scalable line animations for infographics or explainers.
  • UI/UX Prototypes: Animating app interfaces where lines need to stay sharp at different sizes.

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.

Step 9: Advanced Expression Tweaks

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:

  1. Go to Effects > Expression Controls > Slider Control and add it to your shape layer.
  2. Rename the slider to something like “Stroke Width.”
  3. Modify the expression on the Stroke Width property to:

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.

Wrapping It Up

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!