How to word-wrap long text in HTML?

In HTML a very long text is not automatically wrapped. Especially if there are no spaces in your string your browser doesn’t necessarily know where it should break the line.

no-wrap

In most cases you don’t want the people use the horizontal scrollbar to read the entire text but CSS allows you to force the browser to show all the text in multiple lines. CSS offers the properties white-space and word-wrap for this purpose.

div {
    white-space: pre-wrap;      /* CSS3 */
    white-space: -moz-pre-wrap; /* Firefox */
    white-space: -pre-wrap;     /* Opera <7 */
    white-space: -o-pre-wrap;   /* Opera 7 */
    word-wrap: break-word;
}

After applying the above rules on your text containers the result looks as follows.

wrap

Different browsers don't handle long text the same way. In firefox the long text got already wrapped without the CSS rules applied. It was able to detect special characters that were url-encoded and broke the lines on these positions.

firefox-wrap

Nonetheless you should never rely on this automatic detection but teach every browser that you really want to wrap so that you get the same result everywhere.

130 Comments

  1. Good way of telling, and pleasant post to obtain data regarding my presentation focus, which i am going to present in university.

  2. Good way of explaining, and pleasant post to obtain data regarding my presentation topic, which i am
    going to present in academy.

  3. I see you don’t monetize your site, i think there is one opportunity to earn extra money on your
    page, search in google for- idol4jp makes money

  4. I think that everything posted made a lot of sense.

    But, think about this, what if you added a little information? I mean, I don’t wish to tell you
    how to run your blog, but what if you added something that makes people want more?
    I mean How to word-wrap long text in HTML? | Slopjong is a little vanilla.
    You could glance at Yahoo’s front page and see how they create post headlines to grab people interested.
    You might add a video or a related pic or two to grab people interested about what you’ve written. In my opinion,
    it could bring your website a little bit more interesting.

  5. It’s really a nice and useful piece of info. I am glad that you shared this useful
    information with us. Please keep us up to date like this.
    Thank you for sharing.

  6. I read this piece of writing completely regarding the resemblance of newest and preceding technologies, it’s awesome article.

  7. Go ahead and compare the services of different auto transport
    companies and try to look for the best options as most reasonable auto transport rates, for moving
    your vehicle to another place. We offer trusted car shipping and auto transport services without a scratch.
    Hence it is always better to do some research and try to get as much information as possible for auto shipping.

  8. Important Notice: For copyright reasons I did not cowl 7 Minutes Workout Technique (to double outcomes)” as that is trademark technique and it’s
    only obtainable for the buyers of Fat Diminisher.

  9. Go ahead and compare the services of different auto
    transport companies and try to look for the best options as most reasonable auto transport rates,
    for moving your vehicle to another place. They can carry every category of vehicles to
    different places and you do not have to worry about anything.
    Hence it is always better to do some research and try to get as much information as possible for auto shipping.

  10. Estivadores, que prosseguem uma greve que
    está a condicionar fortemente as exportações, assumem tristes atitudes públicas de desrespeito em frente ao parlamento.

  11. Genuinely when someone doesn’t be aware of afterward its up to other people
    that they will assist, so here it takes place.

  12. I think this is amօng thee mօst vittal іnformation ffor me.

    Annd i’m glad reading уοur article.
    Ⲃut ѕhould remark on few ցeneral
    things, Τɦе site style іѕ
    ideal, tһе articles іѕ гeally
    ցreat : D. Ԍood job, cheers

    Also visit mʏ website cd player raadio fοr kids (Bernice)

  13. You actually make it appear really easy together with your presentation however I to
    find this topic to be really something which I think I’d by no means understand.
    It seems too complex and extremely broad for me.
    I am having a look ahead on your subsequent publish, I will attempt to get the grasp of it!

  14. Hello to every body, it’s my first go to see of this website; this webpage consists of amazing and really fine stuff in favor of readers.

  15. Thanks for sharing your thoughts on gaming. Regards

  16. Bajaj Auto has come up with the innovative Bajaj Pulszar 135 LS.
    On internet you wil easily get available with recently updated Yamaha FZ16 price, Yamaha FZ16reviews and access the Yamaha bikes price list.
    Advanced technology has been used to make the bike comfortable offering easy control
    and handling.

  17. I’m completely stoked about it and I’ll maintain you updated as I continue using Testo Fuel.

  18. Right away I am ready to do my breakfast, after having my breakfast
    coming again to read further news.

  19. So, which natural method would you favor to
    go for?

  20. A assortment of games you will uncover in following sites to play them on the web completely cost-free which includes puzzle games
    , action games , word games, sport, arcade, board games etc.

  21. Download FREE! Clash Royale Hack (Floy) for Android,
    iOS and Windows phone!
    Best Clash Royale Hack Tool here : http://clash-royale-hack.com/ !

    Add UNLIMITED GEMS AND GOLD!

  22. This applies to any part of life, health, environment, business, relationships, spiritual life, workplace issues, and everything else.
    Nursing and medical school loans are issued under Title VII of the Public Health Service Act and are not
    reported to the NSLDS. As a consumer you have a choice when it comes
    to buying replacement inkjet cartridges.

  23. The annual rates of herpes simplex virus type-2 infection (also
    called HSV-2) were 10.2 percent making use of tenofovir gel,
    as compared to 21 percent utilizing a placebo gel.

  24. Hi my loved one! I wish to say that this article is
    awesome, nice written and come with approximately all important infos.
    I’d like to peer extra posts like this .

  25. I do not even know the way I ended up right here, but I assumed this post was great.
    I do not recognize who you are but certainly you’re going to a well-known blogger if you happen to are not already.
    Cheers!

  26. Hi there to every body, it’s my first pay a visit
    of this weblog; this blog carries remarkable and really fine information in support of
    visitors.

  27. It sounds like a good deal and many homeowners signed contracts for repairs.
    Even if you saw their ad in a respected publication, always look for references from friends, colleagues or family members for
    a firsthand account of the quality of service
    the company provides. To accomplish either repairs or new installs, a roofing contractor should
    be employed.

  28. Hi friends, how is all, and what you desire to say
    concerning this post, in my view its in fact awesome in
    favor of me.

  29. It sounds like a good deal and many homeowners signed contracts for repairs.
    Even if you saw their ad in a respected publication, always look for references from friends, colleagues or family members for

  30. I tend not to drop many remarks, however I browsed a few responses here How to word-wrap long text in HTML?
    | Slopjong. I actually do have some questions for
    you if you tend not to mind. Could it be only me or does it look
    like some of the comments appear as if they are coming from
    brain dead visitors? :-P And, if you are writing at additional social sites, I
    would like to keep up with you. Could you post a list
    of all of your social networking sites like your linkedin profile,
    Facebook page or twitter feed?

    my site free cms

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>