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

Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
FIDO Alliance
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
panagenda
 
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
UK Journal
 

Recently uploaded (20)

Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
 
Your enemies use GenAI too - staying ahead of fraud with Neo4j
Your enemies use GenAI too - staying ahead of fraud with Neo4jYour enemies use GenAI too - staying ahead of fraud with Neo4j
Your enemies use GenAI too - staying ahead of fraud with Neo4j
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptx
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream Processing
 

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);