Which of the following property controls how spaces, tabs, and newline characters are handled in an element?

space
display
widows
white-space

The correct answer is D. white-space.

The white-space property controls how spaces, tabs, and newline characters are handled in an element. It can be used to add whitespace around elements, to prevent line breaks, or to collapse whitespace.

The following are the possible values for the white-space property:

  • normal: This is the default value. It preserves all whitespace in the element.
  • pre: This value preserves all whitespace in the element, including spaces, tabs, and newline characters.
  • pre-line: This value preserves all whitespace in the element, including spaces, tabs, and newline characters. However, it also inserts a line break after each newline character.
  • pre-wrap: This value preserves all whitespace in the element, including spaces, tabs, and newline characters. However, it also inserts a line break after each newline character, except when the whitespace is at the beginning or end of the element.
  • nowrap: This value collapses all whitespace in the element.
  • inherit: This value inherits the white-space property from the parent element.

For example, the following code will add a space between the two words “Hello” and “World”:

“`html

Hello World

“`

The following code will prevent line breaks in the element:

“`html

Hello World

“`

The following code will insert a line break after each newline character in the element:

“`html

Hello\nWorld

“`

The following code will insert a line break after each newline character in the element, except when the whitespace is at the beginning or end of the element:

“`html

Hello\nWorld

“`

The following code will collapse all whitespace in the element:

“`html

Hello World

“`

The following code will inherit the white-space property from the parent element:

“`html

Hello World

Exit mobile version