SlideShare a Scribd company logo
1 of 7
Truncating longer page titles with an ellipsis – HTML5 Mobile
Web app
http://jbkflex.wordpress.com/2012/01/16/truncating-longer-page-titles-with-an-ellipsis-html5-mobile-
web-app/

Sometimes, while working on HTML5 mobile web apps the text in the page title gets longer than can fit in the page
header bar. Normally in native iPhone apps when the page title gets longer they add an ellipsis to the end of the
truncated text. Check out the image of the iPhone settings – Mail, Contacts, Calendar page below, see how the
long text has been truncated with a trailing ellipsis. Therefore, while building mobile web apps I do the same to give it
an iPhone look and feel. Let’s see how to do it using simple CSS techniques.




                                      Mail, Contacts, Calendar page in iPhone settings

What happens if we do not truncate long text?
I have a very simple setup of a mobile web page below. The page has a header with a very long text. See, how the
text is wrapped in the next line to fit it. This is not very iPhonish and certainly not what we want isn’t it.

.pageHeader

{

    width:100%;

    line-height:40px;

    padding:5px 0 0 5px;
color: #fff;

    display: block;

    background-color:#354F6E;

    border-bottom:1px solid #999999;

    background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #7c9bc0),
color-stop(2%, #416086), color-stop(100%, #293e56));

}




.pageHeader h2

{

    font-size: 17px;

    font-weight: bold;

}




<body>

    <div id="wrapper">

      <header>

        <h2>This is a very very very very very long text</h2>

      </header>

    </div>

</body>


And this is the result,
Long text wrapped in next line

The CSS trick to add ellipsis
Let’s see how to add an ellipsis. The image below shows the same long text, but now I have added an ellipsis using
simple CSS tricks,




                                        Long text truncated with trailing ellipsis
To add an ellipsis I just added the four lines to the CSS style for h2. This is how it is looks now,

.pageHeader h2

{

     font-size: 17px;

     font-weight: bold;

     /*4 properties below are imp for trailing ellipsis*/

     max-width: 210px;

     overflow: hidden;

     white-space: nowrap;

     text-overflow: ellipsis;

}


Now, let’s get over each of them.
1.   max-width limits the width of h2 element to 200px. So it will not grow wider than 200px to auto fit the text.
2.   overflow:hidden ensures that anything that is outside the element boundary will be cut off.
3.   white-space: nowrap ensures that the line is not broken into two. If we do not provide it, the text line will break
     into two and will grow taller to accommodate the text within the maximum width.
4.   And finally, text-overflow:ellipsis adds three trailing dots to the cut off text.
The last CSS rule, text-overflow is a very little used and little known CSS trick, but is an important one.
The full code block is below,

<!DOCTYPE html>

<html>

<head>

<title>Truncating long text with trailing ellipsis...</title>

<meta name="viewport" content="width=device-width; initial-scale=1.0;
minimum-scale=1.0; maximum-scale=1.0;"/>

<style type="text/css">

*{

     margin:0;
padding:0;

}

html,body

{

    font-family:Helvetica;

}

#wrapper

{

    width:320px;

    height:416px;

    overflow:hidden;

    background-color:#ccc;

}

.pageHeader

{

    width:100%;

    line-height:40px;

    padding:5px 0 0 5px;

    color: #fff;

    display: block;

    background-color:#354F6E;

    border-bottom:1px solid #999999;

  background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%,
#7c9bc0), color-stop(2%, #416086), color-stop(100%, #293e56));

}
.pageHeader h2

{

    font-size: 17px;

    font-weight: bold;

    /*4 properties below are imp for trailing ellipsis*/

    max-width: 210px;

    overflow: hidden;

    white-space: nowrap;

    text-overflow: ellipsis;

}




</style>

</head>

<body>

    <div id="wrapper">

      <header class="pageHeader">

         <h2>This is a very very very very very long text</h2>

      </header>

    </div>

</body>

<script type="text/javascript">

    window.addEventListener("load", initApp, false);

    function initApp() {

      setTimeout(function() { window.scrollTo(0,1); }, 20);
}

</script>

</html>

More Related Content

Recently uploaded

Recently uploaded (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

Truncating longer page titles with an ellipsis slideshare

  • 1. Truncating longer page titles with an ellipsis – HTML5 Mobile Web app http://jbkflex.wordpress.com/2012/01/16/truncating-longer-page-titles-with-an-ellipsis-html5-mobile- web-app/ Sometimes, while working on HTML5 mobile web apps the text in the page title gets longer than can fit in the page header bar. Normally in native iPhone apps when the page title gets longer they add an ellipsis to the end of the truncated text. Check out the image of the iPhone settings – Mail, Contacts, Calendar page below, see how the long text has been truncated with a trailing ellipsis. Therefore, while building mobile web apps I do the same to give it an iPhone look and feel. Let’s see how to do it using simple CSS techniques. Mail, Contacts, Calendar page in iPhone settings What happens if we do not truncate long text? I have a very simple setup of a mobile web page below. The page has a header with a very long text. See, how the text is wrapped in the next line to fit it. This is not very iPhonish and certainly not what we want isn’t it. .pageHeader { width:100%; line-height:40px; padding:5px 0 0 5px;
  • 2. color: #fff; display: block; background-color:#354F6E; border-bottom:1px solid #999999; background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #7c9bc0), color-stop(2%, #416086), color-stop(100%, #293e56)); } .pageHeader h2 { font-size: 17px; font-weight: bold; } <body> <div id="wrapper"> <header> <h2>This is a very very very very very long text</h2> </header> </div> </body> And this is the result,
  • 3. Long text wrapped in next line The CSS trick to add ellipsis Let’s see how to add an ellipsis. The image below shows the same long text, but now I have added an ellipsis using simple CSS tricks, Long text truncated with trailing ellipsis
  • 4. To add an ellipsis I just added the four lines to the CSS style for h2. This is how it is looks now, .pageHeader h2 { font-size: 17px; font-weight: bold; /*4 properties below are imp for trailing ellipsis*/ max-width: 210px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; } Now, let’s get over each of them. 1. max-width limits the width of h2 element to 200px. So it will not grow wider than 200px to auto fit the text. 2. overflow:hidden ensures that anything that is outside the element boundary will be cut off. 3. white-space: nowrap ensures that the line is not broken into two. If we do not provide it, the text line will break into two and will grow taller to accommodate the text within the maximum width. 4. And finally, text-overflow:ellipsis adds three trailing dots to the cut off text. The last CSS rule, text-overflow is a very little used and little known CSS trick, but is an important one. The full code block is below, <!DOCTYPE html> <html> <head> <title>Truncating long text with trailing ellipsis...</title> <meta name="viewport" content="width=device-width; initial-scale=1.0; minimum-scale=1.0; maximum-scale=1.0;"/> <style type="text/css"> *{ margin:0;
  • 5. padding:0; } html,body { font-family:Helvetica; } #wrapper { width:320px; height:416px; overflow:hidden; background-color:#ccc; } .pageHeader { width:100%; line-height:40px; padding:5px 0 0 5px; color: #fff; display: block; background-color:#354F6E; border-bottom:1px solid #999999; background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #7c9bc0), color-stop(2%, #416086), color-stop(100%, #293e56)); }
  • 6. .pageHeader h2 { font-size: 17px; font-weight: bold; /*4 properties below are imp for trailing ellipsis*/ max-width: 210px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; } </style> </head> <body> <div id="wrapper"> <header class="pageHeader"> <h2>This is a very very very very very long text</h2> </header> </div> </body> <script type="text/javascript"> window.addEventListener("load", initApp, false); function initApp() { setTimeout(function() { window.scrollTo(0,1); }, 20);