<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/count-the-number-of-lines-inside-a-text-yd6bhtp2j" -->

---
title: Count the number of lines inside a text | daily.dev
description: Learn how to count the number of lines in a text by adjusting the code used to get the width and height of any element using CSS. The demo adjusts the number...
canonical: https://daily.dev/posts/count-the-number-of-lines-inside-a-text-yd6bhtp2j
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Count the number of lines inside a text | daily.dev
og:description: Learn how to count the number of lines in a text by adjusting the code used to get the width and height of any element using CSS. The demo adjusts the number...
og:url: https://daily.dev/posts/count-the-number-of-lines-inside-a-text-yd6bhtp2j
og:image: https://api.daily.dev/og/posts/YD6BHtP2J.png
og:image:alt: Count the number of lines inside a text
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Count the number of lines inside a text

**[CSS Tip](https://daily.dev/sources/csstip)** · 1 min read · 36 upvotes · 1 comments

## Summary

Learn how to count the number of lines in a text by adjusting the code used to get the width and height of any element using CSS. The demo adjusts the number of lines based on the content entered.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://css-tip.com/count-lines/>

## Community discussion

Top comments from developers on daily.dev.

**@yaireo** · 0 upvotes

> I've made a CodePen some years ago which shows how to do that with javascript ofc...
>
> https://codepen.io/vsync/pen/BawdgEd

---

Tags: [#webdev](https://daily.dev/tags/webdev), [#css](https://daily.dev/tags/css)

[View this post on daily.dev](https://daily.dev/posts/count-the-number-of-lines-inside-a-text-yd6bhtp2j)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Count the number of lines inside a text","url":"https://daily.dev/posts/count-the-number-of-lines-inside-a-text-yd6bhtp2j","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/count-the-number-of-lines-inside-a-text-yd6bhtp2j"},"datePublished":"2024-07-29T11:15:01.312Z","dateModified":"2024-08-23T16:20:31.698Z","description":"Learn how to count the number of lines in a text by adjusting the code used to get the width and height of any element using CSS. The demo adjusts the number...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/51850ee8bfeab465c0a84b0f9f8150a4?_a=AQAEuiZ","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/51850ee8bfeab465c0a84b0f9f8150a4?_a=AQAEuiZ","isAccessibleForFree":true,"articleSection":"CSS Tip","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"CSS Tip","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/5d335233e7894c2ea997aa89e1724200","url":"https://daily.dev/sources/csstip"},"commentCount":1,"discussionUrl":"https://daily.dev/posts/count-the-number-of-lines-inside-a-text-yd6bhtp2j","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":36},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":1}],"keywords":"webdev,css","timeRequired":"PT1M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"CSS Tip","item":"https://daily.dev/sources/csstip"},{"@type":"ListItem","position":3,"name":"Count the number of lines inside a text"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/count-the-number-of-lines-inside-a-text-yd6bhtp2j","comment":[{"@type":"Comment","text":"I’ve made a CodePen some years ago which shows how to do that with javascript ofc…\nhttps://codepen.io/vsync/pen/BawdgEd","datePublished":"2024-08-06T09:43:21.268Z","dateModified":"2024-08-06T09:44:04.309Z","url":"https://daily.dev/posts/YD6BHtP2J#c-xI1t3gFxG","author":{"@type":"Person","name":"Yair Even Or","url":"https://daily.dev/yaireo","image":"https://avatars.githubusercontent.com/u/845031?v=4"}}]}
```

