TEXTAREA Wrap Attribute Soft Or Hard
Asked Answered
L

2

1

I read w3schools and MDN to learn how the wrap attribute of <textarea> works. I saw a question here that explains the difference between soft and hard wrap but I can't understand it. Can anyone explain this to me in a more simplified way?

Lucey answered 29/8, 2021 at 14:14 Comment(0)
I
1

wrap: hard breaks long words into smaller (in case cols attribute is set - this will be length of smaller words)

Wrap: hard

For example this form will have output WWWWWWWWWW WWWWWWWWWW WWWWWWWWWW WWWWWWWWWW WWWWWWWWWW WWWWWWWWWW W :

<form>
  <textarea cols="10" wrap="hard">
  WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
  </textarea>
  <input type="submit">
</form>

Wrap: soft

With wrap: soft it will have this output (same as value): WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW

Wrap: off

Also there is option wrap: off, which means, that nothing will be split to more lines. A scrollbar will be added instead. It has no change to output, which will be like with wrap: soft: WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW

<textarea wrap="off">
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
</textarea>
Indusium answered 29/8, 2021 at 14:59 Comment(0)
C
0

Try to play with graphical input. You should notice the difference when the input field size exeeded. For example:

<textarea wrap="hard" cols="20"></textarea>

Will begin new line each 80 chars. Note it's not supported everywhere/

<textarea wrap="soft" cols="20"></textarea>

Will begin new line once displayed width exeeded.
You can also disable line wrap by wrap="off"

Code spinnet to play with (have a look at @Arnav Katyal's answer):
Adding Line Numbers To HTML Textarea

Cuenca answered 9/10, 2023 at 15:30 Comment(1)
Consider, line wraps are actually not newlines, because not contain \n escape charCuenca

© 2022 - 2024 — McMap. All rights reserved.