What's the best way to truncate a URL so that it fits within a layout <p>What is the best way to truncate a URL when displaying it within a web page? I don't mean a link but literally displaying the URL as a value to the user, assuming that the text might be in a container of fixed width and you don't want to wrap or run outside of the container?</p> <p>Is it better to truncate from the end, favouring the early part of the url:</p> <p>eg. http/really.long/urlthaticantf...ere.html</p> <p>Or place the '...' in the middle to favour the start and end of the link as the most value in terms of giving context:</p> <p>eg. http/really.long/ur...aticantfithere.html</p> <p>Also what is a good rule of thumb when choosing how long to make the truncated url? Should you be pessimistic and pick a likely wide character such as capital 'M' and see how many of these fit in the layout? This tends to give really short URLs in general as most characters are much narrower than 'M'.</p> <p>Or should you be optimistic and use a truncation that generally gives a good length but risk overrunning when the URL contains many large characters?</p>