Tidy Up Your Shopify Product Grid: How to Limit Product Names to Two Lines
Hey there, fellow store owners! Let's talk about something that might seem small but can make a huge difference in how professional and polished your Shopify store looks: product name display. You know that feeling when you're scrolling through a collection, and some product titles are super long, pushing everything out of alignment, while others are short and sweet? It creates this uneven, sometimes jarring, look that can really detract from the overall user experience.
Just recently, a store owner named baynojayson brought up this exact pain point in the Shopify Community forums. They were looking for a way to make all product names consistently display on two lines across their entire store, both on desktop and mobile, to achieve a "clean" look. And honestly, it's a brilliant goal! A uniform product grid not only looks better but also makes browsing easier for your customers.
Here's a glimpse of what baynojayson was dealing with – notice how the varying lengths create an inconsistent visual flow:

Why a Consistent Product Grid Matters
Think about it: when you're shopping online, you appreciate a neat, organized layout. Uneven product titles can lead to:
- Visual Clutter: Your product grid looks messy and unprofessional.
- Poor Readability: Long titles can get cut off awkwardly, or push other elements around.
- Inconsistent UI: Product cards end up having different heights, making it harder for customers to quickly scan and compare items.
- Mobile Headaches: These issues are often amplified on smaller screens, where space is already at a premium.
The Community's Solution: A Simple CSS Snippet
Luckily, the Shopify Community is a treasure trove of helpful folks! A sharp community member, mastroke, jumped in with a super effective CSS snippet that perfectly solves this problem. The magic here lies in a property called -webkit-line-clamp, which allows you to limit a block of text to a specific number of lines and then adds an ellipsis (...) if the text overflows.
Here's the code mastroke shared, which baynojayson confirmed "really solved the problem!":
a.card-link.text-current.js-prod-link {
display: -webkit-box;
max-width: 100%;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
white-space: normal;
}
And here's what the result looks like – much cleaner, right?

How to Implement This CSS in Your Shopify Store
Ready to give your product grid a makeover? Here are the steps to add this CSS to your Shopify theme:
Step-by-Step Instructions:
- Backup Your Theme: Before making any code changes, it's always a good idea to duplicate your theme. Go to your Shopify admin, navigate to Online Store > Themes. Find your current theme, click Actions > Duplicate. This way, if anything goes wrong, you can revert to the duplicate.
- Access Your Theme Code: Again, from Online Store > Themes, click Actions > Edit code for your live theme.
- Locate Your CSS File: In the theme editor, look for a file like
base.css,theme.css,global.css, or sometimes a file within anassetsfolder ending in.cssor.scss.liquid. The exact name can vary by theme. Mastroke specifically mentionedbase.cssortheme.css, which are common names. - Paste the CSS Code: Scroll to the very bottom of your chosen CSS file and paste the code snippet provided above.
- Understand the Code (Optional but helpful!):
a.card-link.text-current.js-prod-link: This is the CSS selector. It targets the specific link element that wraps your product name. Important: This selector might need to be adjusted for your specific theme. If the code doesn't work right away, you'll need to use your browser's developer tools (right-click on a product name and select "Inspect") to find the correct class names or element structure for your product titles.display: -webkit-box;and-webkit-box-orient: vertical;: These properties enable the flexible box model, specifically for older WebKit browsers, which is necessary for-webkit-line-clampto work.max-width: 100%;: Ensures the text container doesn't overflow its parent.-webkit-line-clamp: 2;: This is the star of the show! It limits the text to exactly 2 lines. You can change this number if you prefer 1 or 3 lines, for example.overflow: hidden;andtext-overflow: ellipsis;: These work together to hide any text that exceeds the specified line limit and add the "..." at the end, indicating more content is available.white-space: normal;: Ensures text wraps naturally within its container.
- Save and Preview: Click "Save" in the top right corner. Then, go to your online store and check your collection pages, search results, and any other areas where product names are displayed. Test it on different screen sizes (desktop, tablet, mobile) to ensure it looks good everywhere.
A Note on Theme Compatibility
While the -webkit-line-clamp property is widely supported by modern browsers, especially WebKit-based ones (like Chrome, Safari, Edge), it's good practice to test thoroughly. The most crucial part is finding the correct CSS selector for your product titles. The one provided by mastroke (a.card-link.text-current.js-prod-link) is specific to the theme baynojayson was using. Yours might be something like .product-card__title, .grid-product__title, or similar. If you're unsure, a quick inspect element in your browser will point you in the right direction.
Implementing this little CSS tweak can instantly elevate the visual appeal of your Shopify store, giving it that clean, professional edge you're looking for. It's a fantastic example of how a small bit of code, shared by a helpful community, can solve a common design challenge for store owners. Give it a try, and enjoy your perfectly aligned product names!