Word wrap not working

Okay so I know this is an old question but I seriously think there could be some useful clarification of when to use which property. Looking at the existing answers, I feel they offer solutions without explanation so here is my attempt to help with that. For context, by default, the container will not try to break a single long word up because it wants to preserve the word in it’s original form.

With that said, 3 main ways to break up words there is overflow-wrap, word-break, and hypens. I won’t dive too deep into hypens though.

So first off. I see word-wrap is being used in the question but reading the documentation, that is deprecated and some browsers have decided to simply alias it to overflow-wrap. It’s probably preferred not to use that.

The distinction between the two properties is pretty clear in the documentation but for clarity, overflow-wrap really only has two possible values and will detect if a word has been overflowed. If it does, by default it moves the entire word to the next line. If break-word is set, it will only break up the word if the entire word couldn’t be placed on that line.

#fos { font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size:14px;
    font-weight: normal;
    line-height: 18px;
    width: 238px;
    height:38px;
    cursor: pointer;
    overflow-wrap: break-word;
    border:2px solid; }
#sp { }
<div id="fos">
<span id="sp">The longest word ever: pneumonoultramicroscopicsilicovolcanoconiosis and then some.</span>  
</div>

You can see the pneumonoul… long word breaks exactly where it needs to on the next line after it attempts to separate the long word.

Now in contrast, we have word-break. This has more granular properties and actually also has a break-word option. This is synonymous to the above snippet so when to use one or the other I think is pretty trivial.

However, word-break also offers a break-all value which will break the word whenever possible to fit word where it was originally intended. It doesn’t try to figure out if it needs the word to be on a new line or not — it simply shoves the line break where it overflows. The biggest distinction here from the above is that long word we use is now still on the top.

#fos { font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size:14px;
    font-weight: normal;
    line-height: 18px;
    width: 238px;
    height:38px;
    cursor: pointer;
    word-break: break-all;
    border:2px solid; }
#sp { }
<div id="fos">
<span id="sp">The longest word ever: pneumonoultramicroscopicsilicovolcanoconiosis and then some.</span>  
</div>

And then finally for hyphens have their own special way of breaking up words. For more info take a look at the documentation. Also worth noting that different languages have different ways of breaking up words but fortunately the hyphens property hooks into the lang attribute and understands what to do.

Another option people have suggested is using the white-space property which attempts to break up text through spaces. In the example I used, this doesn’t help our situation because the word itself is longer than the container. I think the important thing to note about this CSS property is that this doesn’t attempt to break up words within themselves and rather tries to do it via spaces whenever appropriate.

#fos { font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size:14px;
    font-weight: normal;
    line-height: 18px;
    width: 238px;
    height:38px;
    cursor: pointer;
    white-space: normal;
    border:2px solid; }
#sp { }
<div id="fos">
<span id="sp">The longest word ever: pneumonoultramicroscopicsilicovolcanoconiosis and then some.</span>  
</div>

Hope this helps.

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.

Already on GitHub?
Sign in
to your account

Assignees

@roblourens

Labels

*duplicate

Issue identified as a duplicate of another issue(s)

Comments

@ToniSHernandez

Issue Type: Bug

I attempted to use [alt]Z and [alt]z tp get word wrap to work. When this failed, I clecked on View > Toggle Word Wrap. In either situation, the feature did not work.

VS Code version: Code 1.49.3 (2af0510, 2020-10-02T17:57:01.595Z)
OS version: Windows_NT x64 10.0.18362

System Info

Item Value
CPUs Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz (8 x 1992)
GPU Status 2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
opengl: enabled_on
protected_video_decode: enabled
rasterization: enabled
skia_renderer: disabled_off_ok
video_decode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 15.89GB (4.09GB free)
Process Argv —crash-reporter-id 470139ae-9e22-47f5-9264-1f8c13641922
Screen Reader yes
VM 0%

Extensions (21)

Extension Author (truncated) Version
html-snippets abu 0.2.1
beautify-blade api 1.0.1
es7-react-js-snippets dsz 3.0.0
vscode-npm-script eg2 0.3.13
php-intellisense fel 2.3.14
php-pack fel 1.0.2
vscode-firefox-debug fir 2.9.1
auto-close-tag for 0.5.8
vue-snippets hol 0.1.12
vscode-JS-CSS-HTML-formatter lon 0.2.3
remote-wsl ms- 0.44.5
debugger-for-chrome msj 4.12.11
vetur oct 0.28.0
laravel-blade one 1.24.0
vue-beautify pea 2.0.4
LiveServer rit 5.6.1
vscode-scss-formatter sib 2.0.2
open-in-browser tec 2.0.0
vscodeintellicode Vis 1.2.10
eno Wsc 2.3.20
JavaScriptSnippets xab 1.8.0

@vscodebot

@gjsjohnmurray

Does the problem also happen after you run the Command Palette command to reload with all extensions disabled?

@DarkLite1

We’re having the same issue, not all files will wrap their text at 80 characters but some do. Triggering a reload of the window, ALT + Z or something else does not wrap the text either.

User settings:

image

Workspace settings:

image

Both UserSettings.json and project.code-workspace.json have the option editor.wordWrap: wordWrapColumn but not the value 80.

project.code-workspace.json

{
	"folders": [
		{
			"path": "PowerShell"
		},
		{
			"path": "T:\Prod"
		},
		{
			"path": "C:\Program Files\WindowsPowerShell\Modules"
		}
	],
	"settings": {
		"editor.wordWrap": "wordWrapColumn"
	}
}

The thing I’ve noticed is that wrapping only works in the first folder PowerShell within my vs code project but for files within the other 2 folders. Maybe that helps to narrow it down.

Version: 1.50.0 (system setup)
Commit: 93c2f0fbf16c5a4b10e4d5f89737d9c2c25488a3
Date: 2020-10-07T06:10:52.432Z
Electron: 9.2.1
Chrome: 83.0.4103.122
Node.js: 12.14.1
V8: 8.3.110.13-electron.0
OS: Windows_NT x64 10.0.14393

@DarkLite1

Does the problem also happen after you run the Command Palette command to reload with all extensions disabled?

Just tried this, yes the problem remains when reloading without extensions.

@alexdima

@DarkLite1 Word wrapping can be influenced by folder level settings, and it appears you are using a workspace file with further word wrapping settings. To eliminate the complicated settings setup, could you please create a separate new folder on your machine, open that folder and open a powershell file in that folder. What is the behavior? What settings do you have in your user settings?

Except via settings, word wrapping is disabled when:

  • configuring the editor to be in accessibility mode (like attaching a screen reader or configuring editor.accessibilitySupport): the root cause is that we cannot at this time efficiently transmit the difference between a wrapping point and a new line to screen readers, the solution is to use "editor.accessibilitySupport": "off". When this occurs, there is a status bar message indicating this.
  • when a very large file is opened (we do this to save memory), but this can be forced via "editor.largeFileOptimizations": false. When this occurs, a prompt is shown informing you.

@ToniSHernandez @DarkLite1 Do you perhaps run into one of the two cases I outlined above?

@DarkLite1

Thank you for getting back to me. I’ve tried your suggestion to create a new folder, add a ps1 file and check what happens:

  • The ps1 file is correctly having its lines wrapped at 80 chars as desired
  • The User Settings:
    image

To get back to the two exceptions you suggested, this is not he case for us. It’s a small ps1 file and we don’t have anything special configured.

Correct example from the test:
image

This really is related to multiple folders in the same workspace where wrapping is not respected. At least, that’s what it looks like to me. Because in the base folder ‘PowerShell’ wrapping works but not in the other two.

@jabcross

I’m having a similar issue. I have VSCode opened on a folder with no special configuration, and wordWrapColumn set to 80. It doesn’t work on bounded mode, either.

image

@alexdima

@sandy081 IMHO word wrapping works correctly (or as configured). The problem is that folks have a hard time configuring it.

In the first case, @DarkLite1 is using a multi-folder workspace and has trouble configuring word wrapping. I believe there are workspace level settings and folder level settings at work, but I don’t understand from the provided steps what exactly is misconfigured where. 🤷‍♂️

In the second case I believe @jabcross is trying to configure word wrapping at 80, but the default markdown language specific settings override the user settings.

IMHO both of these are UX problems, i.e. the setting works as configured, but the people have a hard time to configure it how they want it.

@jabcross

@alexdima It does, in fact, only happen in Markdown mode. But a silent default that overrides an explicit setting is a bug. Especially if it doesn’t automatically create a field in settings.json to change it back if wanted.


This does seem to solve the problem.

    "[markdown]": {
        "editor.wordWrap": "bounded"
    },

@sandy081

Assigning to @roblourens to see if there can be any UX improvements can be done with our settings editor for these scenarios.

@roblourens

Labels

*duplicate

Issue identified as a duplicate of another issue(s)

If you are attempting to wrap very long words or hyperlinks within a narrow container, you may experience text overflowing when viewing your results in IE11. This may happen despite using the CSS declaration word-wrap: break-word; in IE 11, but looks fine in other browsers. See below:

word wrap or break overflowing width of container

There are ways of handling long words and URLs using forced breaks, hyphenation, ellipsis, etc). See the terrific article here on the CSS Tricks website: https://css-tricks.com/snippets/css/prevent-long-urls-from-breaking-out-of-container/

What if you do not want a hyphen or ellipsis to appear? Using word-wrap: break-word; overflow-wrap: break-word; word-break: break-all; word-break: break-word; or even the Microsoft CSS Browser Prefix declaration -ms-word-break: break-all;, may not work. It didn’t for me.

The solution, using the HTML, ZERO-WIDTH-SPACE Unicode Character .

CSS

#container { width: 120px; background-color:#ccc; border: 1px solid #aaa; margin: 50px 50px 0; } .break { word-wrap: break-word; }

HTML

<div id="container"> <p>Donec sit amet erat porta, rhoncus dolor nec, <span class="break">scelerisqueaghtrafdssf</span> accumsan leo. Phasellus eu ipsum aliquam, <a class="break" href="www.samplewebsite.com/reallylongurl">www.reallylongwebsiteurl.com/reallylongurl</a> rutrum orci a, pulvinar elit. Aenean auctor dignissim tempus.</p> </div>

You have to insert the unicode character whereever you want the breaks to occur. See the final result below.

word wrap or break in IE 11 with zero space unicode character

Answer by Alberto Curtis

When I’m using word-wrap:break-word with Browser Mode: IE9 Compatibility View and Document Mode: IE7 standards its working perfectly fine. However when I change the Document Mode: IE9 standards, its not working.
I’ve also tried using -ms-word-wrap:break-word however its giving me the same result.,it should work, .your_class_name{word-break:break-word;}, i have tested it in ie7 — ie9 and it breaks the word…,Adding -ms-word-break: break-word; worked for me.,

Stack Overflow for Teams
Where developers & technologists share private knowledge with coworkers

you need to have

table {
    width:100%;
    table-layout:fixed;
}

Answer by Bellamy Shepherd

The solution, using the HTML, ZERO-WIDTH-SPACE Unicode Character ​.,If you are attempting to wrap very long words or hyperlinks within a narrow container, you may experience text overflowing when viewing your results in IE11. This may happen despite using the CSS declaration word-wrap: break-word; in IE 11, but looks fine in other browsers. See below:,There are ways of handling long words and URLs using forced breaks, hyphenation, ellipsis, etc). See the terrific article here on the CSS Tricks website: https://css-tricks.com/snippets/css/prevent-long-urls-from-breaking-out-of-container/,What if you do not want a hyphen or ellipsis to appear? Using word-wrap: break-word; overflow-wrap: break-word; word-break: break-all; word-break: break-word; or even the Microsoft CSS Browser Prefix declaration -ms-word-break: break-all;, may not work. It didn’t for me.

CSS


#container { 
  width: 120px;
  background-color:#ccc;
  border: 1px solid #aaa;
  margin: 50px 50px 0;
}

.break {
  word-wrap: break-word;
}

HTML


<div id="container">
  <p>Donec sit amet erat porta, rhoncus dolor nec, <span class="break">scelerisqueaghtr​afdssf</span> accumsan leo. Phasellus eu ipsum aliquam, <a class="break" href="www.samplewebsite.com/reallylongurl">www.reallylong​websiteurl​.com/reallylongurl</a> rutrum orci a, pulvinar elit. Aenean auctor dignissim tempus.</p>
</div>


Answer by Ila Perez

-max-content it is not supported by IE, according to CanIuse.,So I created a fallback for IE that might help you, by setting .button to display:inline-block:,It’s working, but I don’t want to display the elements inline.,The CSS word-wrap: break-word; works only in display:block; or display:inline-block; elements so you can just use:

I have a small css script that force <a> tag word-wrap in a div. It worked fine on FF, Chrome but didn’t work on IE9. How can I fix it?

.tab_title a{
    word-wrap: break-word;
} 

Answer by Kairi Buck

Note: In contrast to word-break, overflow-wrap will only create a break if an entire word cannot be placed on its own line without overflowing.,Report a problem with this content on GitHub,This example compares the results of overflow-wrap, word-break, and hyphens when breaking up a long word.,Browser compatibility

/* Keyword values */
overflow-wrap: normal;
overflow-wrap: break-word;
overflow-wrap: anywhere;

/* Global values */
overflow-wrap: inherit;
overflow-wrap: initial;
overflow-wrap: revert;
overflow-wrap: unset;

Answer by Nash Miller

Also ran into this issue with the ML anomalies table, where fields like job IDs cannot contain spaces, so long values will overflow the cells in Firefox and Edge.,
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
,This property is being used a couple of times for tables to prevent content from overflowing. Works in Chrome:,@cchaos Reopening — fallback styles in #864 doesn’t seem to have been applied to the word-break property on table cells (screenshot on IE11):

Add fallback to just break-all in FF and IE

Answer by Ariya Abbott

It doesn’t work in IE 8 and 9. Do you have any suggestions for IE 8 and 9 for word-wrap: break-word; ?,I’m sorry that last code is working for me in IE8 at the moment…. but not in IE9. I rechecked,for me it does not seem’s to work on Chrome and firefox.,word wrap is not working in this website in firefox

The word-wrap property accepts two values, one of which is the default:

.selector {
  word-wrap: normal; /* the default */
}

.selector-2 {
  word-wrap: break-word;
}

Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project?
Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of
Treehouse students and alumni in the community today.

Start your free trial

Aoi Asano

I am working on the code challenge for text, font, and list section in CSS, and I don’t know why, but word-wrap property is not working, and I can’t display the ellipse as the instruction indicates.
Any suggestion…??

My code is
.list {
word-wrap: break-text;
}

Thank you!

1 Answer

Dustin Matlock

Dustin Matlock


33,856 Points

Dustin Matlock

Dustin Matlock


33,856 Points

May 14, 2014 1:26am

Should you maybe have: .list { word-wrap: break-word; }

Aoi Asano

Aoi Asano May 14, 2014 1:36am

That worked, Dustin! Thank you so much :)

Aoi Asano

Aoi Asano May 14, 2014 1:36am

That worked, Dustin! Thank you so much :)

Posting to the forum is only allowed for members with active accounts.
Please sign in or sign up to post.

Понравилась статья? Поделить с друзьями:
  • Word wrap normal important
  • Word wrap normal break word
  • Word wrap max width
  • Word worth of gaiden
  • Word world скачать на русском